Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: Simplify parsing a file

by saintly (Scribe)
on Apr 02, 2007 at 18:57 UTC ( [id://607905]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Simplify parsing a file
in thread Simplify parsing a file

The syntax
while( <> ) { }
Will 'automagically' run through every line of each of the files the user specified on the command line. It is the equivalent of:
foreach $ARGV (@ARGV) { open( THISFILE, $ARGV ) || next; while( $_ = <THISFILE> ) { } }
Which is why your script was executing many times per file. UNIX programs traditionally don't automatically create new files from their input, they just slurp in all the input files they're given and then print output directly to STDOUT so it can be redirected. Consider:
$ grep 'foo' thisfile.txt thisOtherFile.txt
Which will run through all the files it's given and print matching lines. Perl allows the programmer to do this kind of task easily with the <> syntax.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found