Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Hash Math

by urbs33 (Initiate)
on Mar 11, 2013 at 14:20 UTC ( #1022800=perlquestion: print w/ replies, xml ) Need Help??
urbs33 has asked for the wisdom of the Perl Monks concerning the following question:

Wisest Monks, I have a fun task that I am hoping that you can help me with. I work in a large backup environment. Suppose I have 8 master servers (environments) each with 3 or 4 media servers and a total jobs count of tens of thousands. I have a script that generates a report and ftps it out for billing and emails a copy for our records. I'd like to summarize the report in the body of the email by looping through the report and pushing the master server, media server and size of each job into a hash, then loop through the hash to add the sizes of each individual media server's jobs together, and provide a total sum of each environment overall. I'm kind of stumped and just trying to read up on hashes and math. Any help would be appreciated.

Comment on Hash Math
Re: Hash Math
by toolic (Chancellor) on Mar 11, 2013 at 14:29 UTC
Re: Hash Math
by tobyink (Abbot) on Mar 11, 2013 at 14:41 UTC

    Something like this?

    use 5.010; use strict; use warnings; use List::Util 'sum'; my %messages; $messages{one} = { from => "Alice", to => "Bob", size => 1000, }; $messages{two} = { from => "Bob", to => "Carol", size => 200, }; $messages{three} = { from => "Carol", to => "Dave", size => 30, }; $messages{four} = { from => "Dave", to => "Eve", size => 4, }; say sum map $_->{size}, values %messages;
    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: Hash Math
by sundialsvc4 (Abbot) on Mar 11, 2013 at 15:54 UTC

    You don’t talk about underlying databases but I feel sure that there must be one, in which case could you not use an SQL query with GROUP BY to simply obtain the statistics directly?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (12)
As of 2014-11-27 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (186 votes), past polls