Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Oops, serveral typos in the code I gave you. Always use -w ! :-)
#!/usr/bin/perl -w use Time::Local; my @now = localtime; my $hour = $now[2]; $now[$_] = 0 for 0..2; # set hour, min, sec to 0; $daychange = timelocal(@now); my @dataSUM = <DATA>; my $sum =0; my $firststart; my $laststop; #my $unixtime; foreach my $line(@dataSUM) { my @lineData = split(/[ \t]+/, $line); my $startime = $lineData[0] if(&is_numeric($lineData[0])) || + die "$lineData[0] not numeric\n"; my $stoptime = $lineData[1] if(&is_numeric($lineData[1])) || + die "$lineData[1] not numeric\n"; # $unixtime = scalar localtime $lineData[1] if(&is_numeric( +$lineData[1])) || die "$lineData[1] not numeric\n"; my $xover_bytes = $lineData[7] if(&is_numeric($lineData[7])) || + die "$lineData[7] not numeric\n"; my $art_bytes = $lineData[9] if(&is_numeric($lineData[9])) || + die "$lineData[9] not numeric\n"; my $list_bytes = $lineData[11] if(&is_numeric($lineData[11])) || + die "$lineData[11] not numeric\n"; my $newnews_bytes = $lineData[13] if(&is_numeric($lineData[13])) || + die "$lineData[13] not numeric\n"; my $lineSum = $xover_bytes + $art_bytes + $list_bytes + $newn +ews_bytes; # $sum += $lineSum; $sum{ ($daychange >= $stoptime ? 'first' : 'second') } += $lineSum; $firststart = ($startime < $firststart) || $firststart ==0 ? $star +time : $firststart; $laststop = ($stoptime > $laststop ) ? $stoptime : $laststop; } map { print "$_ => $sum{$_}\n" } keys %sum; sub is_numeric { my $data = shift; return($data =~ m/^\d+$/); } __DATA__ 1149621887 1150922348 stormchaser 69.0.0.0 69.0.0.0 NG004193 +@net.NET 3 820 156 1757 0 0 0 0 + 0 0 176 1149621900 1150922348 stormchaser 69.0.0.0 69.0.0.0 NG004193 +@net.NET 1 648 80 00 0 0 0 0 + 0 93 1149622376 1150922348 stormchaser 69.0.0.0 69.0.0.0 NG004193 +@net.NET 3 793 243 852 0 0 0 0 + 0 0 268 1149625677 1150922348 stormchaser 213.0.0.0 213.0.0.0 Sinkbad@ +net.net 1 493 0 00 0 0 0 0 + 0 1 1149621887 1151008726 stormchaser 69.0.0.0 69.0.0.0 NG004193 +@net.NET 3 820 156 17570249 0 0 0 0 + 0 0 176 1149621900 1151008726 stormchaser 69.0.0.0 69.0.0.0 NG004193 +@net.NET 1 648 80 00 0 0 0 0 + 0 93 1149622376 1151008726 stormchaser 69.0.0.0 69.0.0.0 NG004193 +@net.NET 3 7932259 243 85227944 0 0 0 0 + 0 0 268
Yields:
first => 5363 second => 110731920

cheers,
--shmem

_($_=" "x(1<<5)."?\n".q/)Oo.  G\        /
                              /\_/(q    /
----------------------------  \__(m.====.(_("always off the crowd"))."
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re^3: storing data in a hash by shmem
in thread storing data in a hash by sunadmn

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (3)
    As of 2020-07-08 03:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?