Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Keep It Simple, Stupid
 
PerlMonks  

Re^2: How to create the varibles with the file names

by softworkz (Monk)
on Nov 15, 2005 at 21:03 UTC ( #508790=note: print w/ replies, xml ) Need Help??


in reply to Re: How to create the varibles with the file names
in thread How to create the varibles with the file names

I'd use File::Find

#!/usr/bin/perl -w use strict; use File::Find; my $dir = "C:\\data\\"; find(\&Do_Something, $dir); sub Do_Something{ if ( -f && /\.txt$/ ) { print "Doing Something $_ \n"; } }


Comment on Re^2: How to create the varibles with the file names
Download Code
Re^3: How to create the varibles with the file names
by duff (Vicar) on Nov 15, 2005 at 21:10 UTC

    Except that File::Find recurses into subdirectories and the OP didn't indicate that recursion was needed.

    Also, there's more conceptual baggage with File::Find. If I'm going to gather the files into an array, how do I do that? How do I not recurse if that's appropriate? Et cetera. It's alot more for someone to have to figure out over a simple glob or readdir

Re^3: How to create the varibles with the file names
by mrpeabody (Friar) on Nov 16, 2005 at 16:26 UTC
    Well, if you're going to use File::Find, you might as well use the saner syntax of File::Find::Rule.
    #!/usr/bin/perl use warnings; use strict; use File::Find::Rule; my $dir = "C:/Windows"; my @files = File::Find::Rule ->file() ->name('*.txt') ->mindepth(1) ->maxdepth(1) ->in($dir); print "$_\n" for @files;
    For a job this simple, though, I would probably use glob().

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2014-04-19 13:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls