Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^6: Recursive search

by perl_mystery (Beadle)
on Dec 17, 2010 at 20:46 UTC ( [id://877684]=note: print w/replies, xml ) Need Help??


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

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); } } }

Replies are listed 'Best First'.
Re^7: Recursive search
by poj (Abbot) on Dec 17, 2010 at 21:04 UTC

    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; }

        Please ignore the second query,changing the order of next as below fixed it,still having trouble with first one

        next if $match_plf_name eq $plf; #print "IN\n"; push @recursive_plfs,$match_plf_name; next if ( not grep { /\Q$match_plf_name\E/i } @plf_fil +es); recursion($match_plf_name);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://877684]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found