Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: confused with summing certain elements from an array

by moritz (Cardinal)
on Nov 20, 2007 at 12:46 UTC ( [id://651914]=note: print w/replies, xml ) Need Help??


in reply to confused with summing certain elements from an array

A hash is not sorted, by definition. You can sort the keys when you print it, though.
my %counts; for (0 ... $#out){ $counts{$out[$_]} += $out1[$_]; }
should build the hash.

Update: the Perl 6 solution is much prettier, btw:

for @out Z @out1 -> $char, $count { %hash{$char} += $count; }

Replies are listed 'Best First'.
Re^2: confused with summing certain elements from an array
by Zen (Deacon) on Nov 20, 2007 at 14:51 UTC
    Looks ambiguous to me. "For array iterator array1 points to scalar var and count var, increment hash at var by count" if I had never seen perl 6 code before.

Log In?
Username:
Password:

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

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

    No recent polls found