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;

In reply to Re: searching for multiple lines from outfile and printing them all in the final outfile by Marshall
in thread searching for multiple lines from outfile and printing them all in the final outfile by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.