in reply to Re^4: Recursive search
in thread Recursive search

perl mystery:

You forgot perldoc chomp. Alternatively, you can remove the $ from your regex.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^6: Recursive search
by perl_mystery (Beadle) on Dec 17, 2010 at 20:46 UTC

    I did try chomp as below,didnt make a difference?

    sub recursion { my $plf = shift; print "\nPLF in recursion:$plf\n"; open my $fh, '<', $plf or die "could not open '$plf' $!"; chomp $fh; foreach (my $line = <$fh>) { chomp $line; print "LINE:$line"; if($line =~ /\/(.+?\.plf)/) { print "LINE CONDITION:$line"; #print $1; $match_plf_name = $1; next if $match_plf_name eq $plf; push @recursive_plfs ,$match_plf_name; recursion($match_plf_name); } } }

      try

      while (my $line = <$fh>) # not foreach
      poj

        Thanks,that worked.My below regex is failing for "script_rev1.1.plf",is it because \w is alphanumberic and doesnt match a "."(dot),can u pls suggest how to change the regex to match this awell

        if($line =~ /\/$(\w+\.plf)/)

        2. After pushing the "$match_plf_name" to "@recursive_plfs,when I try to print it,I only see the first element pushed getting printed,why only one element is getting stored in the array?

        foreach my $plf (@plf_files) { #print $plf; if (grep (/\Q$plf\E/i,@file)) { push @recursive_plfs,$plf; recursion($plf); } } sub recursion { my $plf = shift; #print "\nPLF in recursion:$plf\n"; open my $fh, '<', $plf or die "could not open '$plf' $!"; while (my $line = <$fh>) { chomp $line; #print "\nLINE:$line"; if($line =~ /\/(\w+\.plf)/) { #print "LINE CONDITION:$line"; $match_plf_name = $1; print "MATCH PLF:$match_plf_name\n"; next if $match_plf_name eq $plf; next if ( not grep { /\Q$match_plf_name\E/i } @plf_fil +es); print "IN"; push @recursive_plfs,$match_plf_name; recursion($match_plf_name); } } } foreach my $matchplf (@recursive_plfs) { print $matchplf; }