Given that you have this code already (which would be displayed in your post as follows, if you just put <code>...</code> tags around the code):
my $mech = WWW::Mechanize->new(); $mech->get($url); $mech->form_name('loginform'); $mech->field(login => $username); $mech->field(passwd => $password); $mech->click(); my $outpage = $mech->content(); open(OUTFILE, ">$outfile"); print OUTFILE "$outpage";
If it's true that the contents of "$outpage" include a string that matches this regular expression:
/You have \d+ unread messages/
Then you just need four more statements: match and capture that string in $outpage, open your "final" output file, write the captured string to the output file, and close the file. If you need to see the code for that...
if ( $outpage =~ /(You have \d+ unread messages)/ ) { open( FINAL, ">", "make_up_a_file_name" ) or die $!; print FINAL $1,"\n"; close FINAL; }
If that regex doesn't match, you'll need to check the actual contents of "$outpage", and figure out how the regex would need to change in order to match the desired phrase.

In reply to Re: Searching for a string in outfile by graff
in thread Searching for a string in outfile by ysksai

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.