Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Traversing directories recursively

by RaduH (Scribe)
on Nov 20, 2007 at 20:19 UTC ( #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
Node Status?
node history
Node Type: note [id://651991]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2019-07-21 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (7 votes). Check out past polls.

    Notices?