Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Creating hash of arrays (in a faster way)

by BrowserUk (Pope)
on Nov 01, 2013 at 11:00 UTC ( #1060741=note: print w/ replies, xml ) Need Help??


in reply to Creating hash of arrays (in a faster way)

I'd do it this way. I doubt it is any faster than your's, but destroying the input array by a thousand paper cuts seems gratuitous:

@cols = qw(min max sum min max sum);; @values = qw(1 3 4 7 8 9);; push @{ $hash{ $cols[ $_ ] } }, $values[ $_ ] for 0 .. $#values;; pp \%hash;; { max => [3, 8], min => [1, 7], sum => [4, 9] }

I think the real question here is: where do the inputs arrays come from? Is it necessary to build them before constructing the array, or could the hash be built directly from wherever the arrays are populated from?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: Creating hash of arrays (in a faster way)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-08-22 13:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (158 votes), past polls