in reply to Confusion due to hash
I'm not quite sure where you are going with this, but it seems to me that you need two hashes:
use strict; use warnings; use Data::Dumper; my %hash= (10=>1, 20=>2, 30=>1, 40=>2); my %rhash; map {$rhash{$hash{$_}} += $_} keys %hash; print Dumper (\%hash); print Dumper (\%rhash);
Prints:
$VAR1 = '%hash'; $VAR2 = { '40' => 2, '30' => 1, '10' => 1, '20' => 2 }; $VAR1 = '%rhash'; $VAR2 = { '1' => 40, '2' => 60 };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Confusion due to hash
by duckyd (Hermit) on Jan 31, 2006 at 01:44 UTC | |
by GrandFather (Saint) on Jan 31, 2006 at 01:51 UTC |