Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Simplify parsing a file

by myrrdyn (Novice)
on Apr 02, 2007 at 18:36 UTC ( [id://607895]=note: print w/replies, xml ) Need Help??


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

instead of using <> to run through the files, you could do something like:

That's excellent. I'll give that a shot. But can you tell me why the camel book says to do it this way if it doesn't really work?

For the regex part, you're right that that would work for standard HTML, but I have to parse JSP pages too, and they are allowed to nest tags like that. I'll try your while loop and see how that works, though.

As for the sadness of monks, I apologize. The reason I did it this way was to familiarize myself with syntax, standard perl functions, and little gotchas that are inherent in any language. Once I feel proficient with this skill, I'll be happy to keep you guys smiling :)

Replies are listed 'Best First'.
Re^3: Simplify parsing a file
by saintly (Scribe) on Apr 02, 2007 at 18:57 UTC
    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://607895]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-25 19:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found