in reply to confused with summing certain elements from an array
I want to make a hash contains as keys the unique elements from the @out and as values the sums of the letters from the @out1. Also I want the hash to be sortedYou can do this:
That looks silly to me though... why would the data be in parallel arrays to begin with?my %counts; while (my $key = shift @out) { $counts{$key} += shift @out1; }
Also I want the hash to be sortedHashes aren't sorted.
You can iterate the keys of the hash in order as follows:
print "$_: \t$counts{$_}\n" for sort keys %counts;
-David
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: confused with summing certain elements from an array
by GrandFather (Saint) on Nov 20, 2007 at 19:56 UTC |
In Section
Seekers of Perl Wisdom