Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Hash Math

by urbs33 (Novice)
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.

Replies are listed 'Best First'.
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 toolic (Bishop) on Mar 11, 2013 at 14:29 UTC
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1022800]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2018-06-23 11:25 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.