Re: Getting all file paths

2007-03-26 Thread David Cantrell
On Fri, Mar 23, 2007 at 10:25:54AM -0500, Daniel T. Staal wrote:
 On Fri, March 23, 2007 7:52 am, [EMAIL PROTECTED] said:
  #!/usr/bin/perl -w
 I normally see 'use warnings;' listed instead of the -w switch, but that's
 mostly preference.

'use warnings' doesn't work in 5.005.

Obviously this isn't an issue if you're only ever working on OS X, but
needlessly restricting your code to particular versions of perl is a bad
habit to get in to, because you *will* get bitten by it if you share
your code with other people.

-- 
David Cantrell | top google result for internet beard fetish club

There are many different types of sausages.  The best are
from the north of England.  The wurst are from Germany.
  -- seen in alt.2eggs...


Getting all file paths

2007-03-23 Thread JYOUNG79
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.

Jay

#!/usr/bin/perl -w

use File::Find;

%files = ();

find(sub { if (!/^\./  !-d) { $files{$_} = $File::Find::name } }, 
/Volumes/Server/Folder/Path/);

print $files{sku123};  # example of getting item out of hash


Re: Getting all file paths

2007-03-23 Thread kurtz le pirate
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] wrote:

 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. 

have a look at http://www.cs.cf.ac.uk/Dave/PERL/node69.html

-- 
klp


Re: Getting all file paths

2007-03-23 Thread Daniel T. Staal

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.
---



Re: Getting all file paths

2007-03-23 Thread kurtz le pirate
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (Daniel T. Staal) wrote:

 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.


oops... read to quickly the first time... i suggest :

  push (@{$files{$_}},$File::Find::name);



-- 
klp


Re: Getting all file paths

2007-03-23 Thread Sherm Pendley

On Mar 23, 2007, at 8:52 AM, [EMAIL PROTECTED] wrote:

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.


Those aren't part of File::Find - they're File test operators. For  
a full list, have a look at perldoc -f -X, or just open up perlfunc  
in ShuX - they're the first function listed.


Just don't ask me why they're called operators, but documented in  
perlfunc instead of perlop... :-(


sherm--

Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net




Re: Getting all file paths

2007-03-23 Thread jay

Hi Kurtz, Daniel, and Sherm,

Thanks so much for your replies.  I really appreciate it!!  I'll work  
with the examples you sent as well as take a peek at the perldoc -f -X.


Thanks again for taking the time to help with this!  :-)

Jay

On Mar 23, 2007, at 1:12 PM, kurtz le pirate wrote:

In article  
[EMAIL PROTECTED],

 [EMAIL PROTECTED] (Daniel T. Staal) wrote:

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.



oops... read to quickly the first time... i suggest :

  push (@{$files{$_}},$File::Find::name);



--
klp