Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Subroutine to Search Subdirectories Failing at Filehandle Test

by Perlbotics (Bishop)
on Apr 02, 2009 at 22:24 UTC ( #755139=note: print w/replies, xml ) Need Help??


in reply to SOLVED: Subroutine to Search Subdirectories Failing at Filehandle Test

Two changes fixed this:

sub search_dir{ my $sub_name = shift; local *SUB; # <---- 1st: In order to have a new *SUB for each recu +rsion... opendir SUB, $sub_name or die "Couldn't open the specified directo +ry: $!"; while(my $file = readdir(SUB)){ next if $file eq "." or $file eq ".."; next if $file eq "output.txt"; $file = "$sub_name/$file"; # <---- 2nd: since you didn't chdir +... print $file, "\n"; if(-d $file){ search_dir($file); }elsif($file =~ /\$\$/){ print OUTPUT "Possible \$\$ file found: $file\n"; } } #close SUB; }
As ikegami already said, File::Find is your friend.

  • Comment on Re: Subroutine to Search Subdirectories Failing at Filehandle Test
  • Download Code

Replies are listed 'Best First'.
Re^2: Subroutine to Search Subdirectories Failing at Filehandle Test
by BJ_Covert_Action (Beadle) on Apr 03, 2009 at 15:51 UTC
    Beautiful. It worked like a charm. Thank you oh so very much friends.

    Cheers.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2020-10-22 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (225 votes). Check out past polls.

    Notices?