It is assumed that the the order represents the tree's order. The problem is that the tree has some structure errors -- parents are missing in certain locations. I want to create something that would create the missing paths where necessary. For example:Valentine's Day Valentine's Day|Cards Valentine's Day|Flowers Valentine's|Candy Valentine's|Telegrams
Valentine's Day Valentine's Day|Cards Valentine's Day|Flowers Valentine's Valentine's|Candy Valentine's|Telegrams
I realize the above structure makes no sense, but I wanted to illustrate the problem with my current script. It won't notice 'Valentine's' as a path that needs to be created, because the term exists in the previous path. I think I need to tighten my regex, but I am not sure. Can someone help me out? Thanks!
use strict; #use warnings; use Data::Dumper; while(<DATA>) { chomp; my $path = $_; my @paths = split /\|/, $path; my $parent = $paths[-2]; my $child = $paths[-1]; my $prev_path; if ($prev_path !~/^$parent$/) { my $message = 'created new path!'; my @new_paths = @paths; my $discard = pop @new_paths; my $new_path = join '|', @new_paths; print $new_path . "\t" . $message . "\n"; } print $path . "\n"; $prev_path = $path; } __DATA__ Valentine's Day Valentine's Day|Cards Valentine's Day|Flowers Valentine's|Candy Valentine's|Telegrams
In reply to Tree path analyzer regex problem (maybe other issues)? by bryank
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |