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

Re: searching for multiple lines from outfile and printing them all in the final outfile

by Marshall (Canon)
on May 16, 2009 at 16:17 UTC ( [id://764425]=note: print w/replies, xml ) Need Help??


in reply to searching for multiple lines from outfile and printing them all in the final outfile

I am also unsure as what problem you are having. As a suggestion, I would move the open of FINAL outside the "if". The ">" open will create a new blank file. >> would append an existing file. If you have a bunch of these "if" statements, you would only get the output of the last one! if you keep reopening the FINAL file for every if.

Also since it sounds like the output file doesn't have many lines in it, you may find it more convienent to finish writing it, close it, then open it for read, possibly just reading it all into memory at once. And do the search for what you want all at once rather than on a line by line basis as you go - this depends upon what you are looking for in the output.

I've got a number of gizmos that parse webpages, and often as another poster suggested, it is easier to do this in steps (eg, don't try to do it all with one regex). Do it in a couple of smaller steps.

Update: Oh another point, I see you are on Windows which allows spaces in the file names. You will save yourself a lot of grief if you start avoiding that feature. Your code will be more portable and you won't have to double quote the filename say in a type command on windows. Use an underscore _ perhaps like final_output.txt instead of the space.

my $output = $mech->content(); open(OUTFILE, ">", "$outfile"); print OUTFILE "$output"; open( FINAL, ">", "final output.txt" ); if ( $output=~ /(line i want )/ ) { print FINAL "$1"; } close FINAL;
  • Comment on Re: searching for multiple lines from outfile and printing them all in the final outfile
  • Download Code

Log In?
Username:
Password:

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

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

    No recent polls found