Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^13: Computing results through Arrays

by aaron_baugher (Curate)
on Jun 24, 2015 at 23:07 UTC ( #1131873=note: print w/replies, xml ) Need Help??


in reply to Re^12: Computing results through Arrays
in thread Computing results through Arrays

I may still not understand exactly what you're trying to do. But if you want to keep track of a max value for each time/database at the same time that you're keeping a total for the purpose of averaging, you could do something like this inside your while() loop:

$h{$ddhh }{$database}{total} += $speed; $m{$ddhhmm}{$database}{total} += $speed; $h{$ddhh }{$database}{max} = max(($h{$ddmm}{$database}{max} || 0), + $speed); $m{$ddhhmm}{$database}{max} = max(($h{$ddmm}{$database}{max} || 0), + $speed);

You can use the max() function from List::Util or write your own. Now later in the code where you used to access the total speed with $h{$timestamp}{$database}, you'll change that to access it as $h{$timestamp}{$database}{total}. And that makes room to keep track of the maximum value for each one in $h{$timestamp}{$database}{max}. Make sense?

Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.

Replies are listed 'Best First'.
Re^14: Computing results through Arrays
by yasser8@gmail.com (Novice) on Jun 26, 2015 at 09:32 UTC
    Thanks, this is what exactly I was looking out for. Once again thanks a lot.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1131873]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2020-05-27 06:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (153 votes). Check out past polls.

    Notices?