Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Fileopening question

by planetscape (Chancellor)
on Apr 03, 2006 at 09:41 UTC ( #540888=note: print w/replies, xml ) Need Help??


in reply to Fileopening question

This is the sort of thing I usually use for such purposes. Note this is recursive and therefore will search subdirectories also. :-)

#!/usr/bin/perl -w # Recurse directories to find .txt files use strict; use File::Find; my $file = ''; my $dir = ''; @ARGV = qw(.) unless @ARGV; # current dir unless otherwise specified $dir = shift @ARGV; sub process_file { return unless -f; #skip directories $file = $_; if ($file =~ m/\.(txt)/si) { # do stuff here } } find(\&process_file, $dir);

HTH,

Update: Deleted a spurious line from the code. The original is from an example on recursive editing, and I stripped some (but not all) of the non-relevant code. Oops. ;-)

planetscape

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2022-01-17 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (51 votes). Check out past polls.

    Notices?