On Fri, March 23, 2007 7:52 am, [EMAIL PROTECTED] said:
> Hi,
>
> I'm still new to Perl and was just curious if the code below is ok to
> use. Also, can someone direct me to more information about file::find?
> I'd like to know if -d means directory (I assume it does) as well as -f
> and other options that may apply.  Basically, I want to loop thru all
> files in a folder (including nested folders too) and then create a hash
> whose key is the file name and value is the full path to the file.  I
> don't want to grab any paths to just directories or invisible files.
> Thanks.

This type of question should really be directed to the perl-newbies list,
but I'll say what I can.

Documentation on File::Find can be found online at:
http://search.cpan.org/~nwclark/perl-5.8.8/lib/File/Find.pm

It should also be in your local man pages.

Other comments:

> #!/usr/bin/perl -w

I normally see 'use warnings;' listed instead of the -w switch, but that's
mostly preference.

I would suggest you also put in 'use strict;'.

> use File::Find;
>
> %files = ();

You mean 'my %files'.  You also don't need the '=()', but it doesn't hurt
either.

> find(sub { if (!/^\./ && !-d) { $files{$_} = $File::Find::name } },
> "/Volumes/Server/Folder/Path/");
>
> print $files{"sku123"};  # example of getting item out of hash

I'm leaving these alone for the moment.

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------

Reply via email to