theantler has asked for the wisdom of the Perl Monks concerning the following question:

Was looking for in the tutorial section without luck .. I read you can have a reference to a hash that can describe the file, that sounds interesting! How to do this?

UPDATE: THANK YOU GUYS!

Replies are listed 'Best First'.
Re: File:find tutorial/introduction
by Corion (Patriarch) on Apr 12, 2010 at 08:01 UTC

    I think to get "(a reference to) a hash that can describe the file", you have to look at Path::Class->stat, which uses File::stat. Otherwise, have a look at the plain stat call to find information about a file. Path::Class also has Path::Class::Iterator, which tries to be like File::Find. The basic skeleton for File::Find which I use is:

    use File::Find; my @found; find(sub { push @found, $File::Find::name; }, @directories); ...

    This has the disadvantage of first collecting all files instead of processing them as they become available, but it has the advantage of a very simple callback.

      but it has the advantage of a very simple callback.

      I wouldn't call
      my @found; find(sub { push @found, $File::Find::name; }, @directories); for (@found) { next if !check($_); ... }
      simpler (or more complex) than
      my @found; find(sub { push @found, $File::Find::name if check($File::Find::name); + }, @directories); for (@found) { ... }

      The disadvantage of the former approach is that you only have access to the fully qualified name without doing extra work. If you think that's not an issue, you might as well use cleaner File::Find::Rule.

      Update: Added "not" in "If you think that's not an issue". Oops!

Re: File:find tutorial/introduction
by Anonymous Monk on Apr 12, 2010 at 07:58 UTC