Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Traversing directories recursively

by RaduH (Scribe)
on Nov 20, 2007 at 20:19 UTC ( [id://651991]=note: print w/replies, xml ) Need Help??


in reply to Traversing directories recursively

Try this:
sub browse($) { my $path = $_[0]; #append a / if missing if($path !~ /\/$/) { $path .= '/'; } #loop through the files contained in the directory for my $eachFile (glob($path.'*')) { #if the file is a directory if(-d $eachFile) { #browse directory recursively browse($eachFile); } else { your file processing here } } }#browse
It seems shorter (if you ignore/eliminate the makeup I added to enhance readability) and much simpler than what you have and works. Hope this helps.

Replies are listed 'Best First'.
Re^2: Traversing directories recursively
by codeacrobat (Chaplain) on Nov 21, 2007 at 19:30 UTC
    Nice for a programming exercise. But one should should not reinvent the wheel. I'd use something that =~ m/File::Find(?:::Rule)?$/ :-)

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-03-29 04:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found