Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Is this more what you were thinking of?

#!/usr/bin/perl use warnings; use strict; my %hours; while(<DATA>) { next unless $_ =~ /\w+/; my @F = split; if ( $F[2] =~ /(\d{2})\:\d{2}:\d{2}/ ) { $hours{$1}{value} += $F[3]; $hours{$1}{count}++; } } for ( sort { $a <=> $b } keys %hours ) { print "Sum at $_ hours is ", $hours{$_}{value}, "\n"; print "Count at $_ hours is ", $hours{$_}{count}, "\n"; } __DATA__ 26603 2010-10-09 00:00:23 38784360.8136 26603 2010-10-09 00:01:23 36529742.6667 26603 2010-10-09 00:02:23 36966880.8000 26603 2010-10-09 00:03:23 35666405.8667 26603 2010-10-09 01:05:23 35600190.6667 26603 2010-10-09 02:06:23 39175029.2000 26603 2010-10-09 03:07:23 35386478.4000 26603 2010-10-09 04:08:27 35773482.7500 26603 2010-10-09 05:09:23 39073367.5714 26603 2010-10-09 06:10:23 34379049.8667 26603 2010-10-09 07:11:24 33984045.7705 26603 2010-10-09 09:12:23 36276301.8305 26603 2010-10-09 10:13:23 37248366.0000
which yields the results:

C:\Code>perl values_per_hour.pl Sum at 00 hours is 147947390.147 Count at 00 hours is 4 Sum at 01 hours is 35600190.6667 Count at 01 hours is 1 Sum at 02 hours is 39175029.2 Count at 02 hours is 1 Sum at 03 hours is 35386478.4 Count at 03 hours is 1 Sum at 04 hours is 35773482.75 Count at 04 hours is 1 Sum at 05 hours is 39073367.5714 Count at 05 hours is 1 Sum at 06 hours is 34379049.8667 Count at 06 hours is 1 Sum at 07 hours is 33984045.7705 Count at 07 hours is 1 Sum at 09 hours is 36276301.8305 Count at 09 hours is 1 Sum at 10 hours is 37248366 Count at 10 hours is 1 C:\Code>

In reply to Re: Calculate hourly averages by dwm042
in thread Calculate hourly averages by addyrocker

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-19 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found