as a suggestion, I'd scope your variables and create $mechanize on each iteration. This may help the garbage collection to free up the memory
#!/usr/bin/perl use WWW::Mechanize; use HTTP::Cookies; use Stream::Reader; $url="https://mymail.company.com"; my $username = "XXXXXXXXXX"; my $password = "xxxxxxxxxx"; CHK_STRT: { my $mechanize = WWW::Mechanize->new(autocheck => 1); $mechanize->cookie_jar(HTTP::Cookies->new()); $mechanize->credentials($username,$password); $mechanize->get($url); $mechanize->get("https://mymail.company.com/exchange/User/Inbox/?Cmd +=contents&Page=1"); my $page = $mechanize->content(); $mechanize->get("https://mymail.company.com/exchange/User/Inbox/Sub_ +dir_1/?Cmd=contents&Page=1"); my $Sub_1>get("https://mymail.company.com/exchange/User/Inbox/Sub_di +r_2/?Cmd=contents&Page=1"); my $Sub_2 = $mechanize->content(); $mechanize->get("https://mymail.company.com/exchange/User/Inbox/sub_ +dir_3/?Cmd=contents&Page=1"); my $Sub_3 = $mechanize->content(); $mechanize->get("https://mymail.company.com/exchange/User/Inbox/sub_ +dir_4/?Cmd=contents&Page=1"); my $Sub_4 = $mechanize->content(); open(FH, ">school.txt") or die " Can't open school file\n"; binmode FH, ':utf8'; print FH $page; print FH $Sub_1; print FH $Sub_2; print FH $Sub_3; print FH $Sub_4; close(FH); my @substrings = ( 'icon-msg-unread.gif' ); my $handler; open( $handler,'<','school.txt' ) or die "can't Reopen the file\n"; my $stream = Stream::Reader->new( $handler ); my $result = $stream->readto(\@substrings, {Mode => 'E'}); #This mod +e returns false $emails = 1; close $handler; open(WR, ">announce.txt"); if( $result ) { print WR "new\n"; $emails++; } elsif( $stream->{Error} ) { die "Fatal error during reading file!\n"; } else { print WR "old\n"; } close WR; } unlink('C:/MC/school.txt'); system 'ftp -s:ftpc ftp.server > Log.log'; unlink 'Log.log'; sleep(60); goto CHK_STRT;
I haven't tried this code, but it may make a starting point.

In reply to Re: memory consumption by bangers
in thread memory consumption by moked

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.