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

Re: using File::Find for reading files in order

by hbm (Hermit)
on Feb 04, 2009 at 13:50 UTC ( #741279=note: print w/ replies, xml ) Need Help??


in reply to using File::Find for reading files in order

Another tip: In the find sub, $_ is equivalent to File::Find::name, so you could do:

find sub { push @messages, $_ if (-d $_ && !/^\.+$/); }, $dir


Comment on Re: using File::Find for reading files in order
Download Code
Re^2: using File::Find for reading files in order
by merlyn (Sage) on Feb 04, 2009 at 15:14 UTC
    In the find sub, $_ is equivalent to File::Find::name
    Nope. $_ holds the name relative to the current directory at the time of the subroutine call, which in the default case has been chdir'ed to the location of the file. But $File::Find::name is always relative to the original directory.

    So they aren't the same. Definitely different uses. You can use $_ inside the subroutine, but if you want to save the name for later, you want to use $File::Find::name. And in fact, it'd be wrong to use $File::Find::name within the subroutine, because your relative name would have been applied twice. Ouch.

      merlyn, Thanks for clarifying. I was hesitant to say "equivalent"; even to say anything other than "you can shorten your code..." And now I've reread the doc, a Good Thing.

      I've reread the OP too, and I think the claimed output is misleading. Surely it is more like the following? (In which case my suggestion can be stricken, as it would only yield the files.)

      /path/to/File 1 /path/to/File 10 /path/to/File 100 /path/to/File 2 /path/to/File 20 ...

      Whew.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2014-08-30 05:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls