in reply to split snafus

You have information loss because the first item of a pair is considered the key, and you have the key 1 multiple times.

What do you want the result to be? A list of items with key 1? or the hash the other way round?

Perhaps my %hFields = reverse @tfields; is what you want?

Replies are listed 'Best First'.
Re^2: split snafus
by manav_gupta (Acolyte) on Jun 17, 2008 at 11:40 UTC
    Sorry, I want the total for each element. With the above code and the following snippet:
    while (($value,$key) = each %hFields) { if (defined($rHash->{$key})) { $rHash->{$key}->{'count'}+= $value; } else { $rHash->{$key}->{'count'} = $value; } $total+= $value; } } print "Total = $total\n", Dumper ($rHash);
    I get:
    Total = 146047 $VAR1 = { '1213_Device' => { 'count' => 1181 }, 'RTTMon_Common_Probe' => { 'count' => '2' }, 'Cisco_Temperature_Sensor' => { 'count' => 24 }, 'Cisco_Memory_Pool' => { 'count' => 2598 }, 'Cisco_Voltage_Sensor' => { 'count' => 496 }, 'Cisco_CBQoS_Class' => { 'count' => 6250 }, 'RTTMon_Jitter_Probe' => { 'count' => 175 }, 'Cisco_CPU_Unit' => { 'count' => 116 }, 'Cisco_Power_Supply' => { 'count' => '1' }, 'Cisco_CBQoS_Match' => { 'count' => 9068 }, 'Cisco_CBQoS_RED' => { 'count' => 3470 }, 'IETF_IF' => { 'count' => 119169 }, 'Cisco_Fan_Unit' => { 'count' => 3497 } };