Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: How can I run an folder full of text files through a perl script?

by bart (Canon)
on Dec 08, 2012 at 22:31 UTC ( #1007934=note: print w/replies, xml ) Need Help??

in reply to How can I run an folder full of text files through a perl script?

If all text files are on the same depth, then either you can depend on the shell globbing (except on Windows) to get all files into the @ARGV array, or use perl's own glob. (Unlike on Linux, Windows doesn't expand *.txt on the command line to a list of all files ending in ".txt". Yo uhave to take care of that yourself.)

Using glob can be done, for example, like this:

chdir $dir; @ARGV = glob "*.txt";
and now you can just use while(<>){...}. On each line, $ARGV contains the current file name, and eof can be used to detect when the current file is finished, and the next file will start to be used.

Or you can just loop through the file list yourself and open each file in turn.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007934]
[Corion]: The code is 00000000, as always, no?
[GotToBTru]: I remember hearing about somebody misplacing a list of code phrases or something
[marto]: 12345
[GotToBTru]: the "nuclear codes" are in the case cuffed to the wrist of some guy
[LanX]: not always
[LanX]: it's up to the Supreme commander
[GotToBTru]: we don't have one of those ;)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2017-01-20 12:41 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (174 votes). Check out past polls.