Hello Monks.
I wrote a little script, for sorting out some traffic statistics. It parse log file putting all into big hash(I guess its gettin really big) and then print formatted output. The problem is when size of log files exceed about 200mb, it eats all the memory(512mb) and I got error: "Out of memory during request for 1012 bytes, total sbrk() is 536797184 bytes!"
What should I do with that?
Here is my code:
while (<LOG>){ my ($source, $sport, $to, $dport, $proto, $packs, $bytes) = sp +lit; if ( $total{"$source$dport"}{'from'} ) { # if source exist $connects{"$source$dport"}++; if ($total{"$source$dport"}{'to'}) { # and destination + exist - summarizing $total{"$source$dport"}{'bytes'}+=$bytes; } else { print "oops"; } # this seem we can't get here, +but I don't get why... } else { $total{"$source$dport"} = { "from" => $source, "to" => +"$to:$dport", "bytes" => $bytes } } $total+=$bytes; }
Log look like that:
10.0.1.10 2484 10.10.10.5 445 6 1 48

In reply to How to save memory, parsing a big file. by idle

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.