A
Antonio Quinonez
I am trying to sort hash elements with the following structure:
%hashname{$npanxx}{$node}{$plan} = cost
so that i get plans ordered by lowest to greatest cost, in the format
of:
$npanxx:: $node :: $plan :: cost
i have the solution for SET 1(see below), where the second key ($node)
completes the hash member and gives me back what i want. I just can't
solve for the higher order hash. any help would be appreciated. sample
data for SET 1 and SET 2 and code for SET 1 follows:
%RS = ();
###SET 1
$RS{206231}{SEA} = 1.2;
$RS{206231}{NYC} = 11.2;
$RS{206231}{LAX} = 4.2;
$RS{206231}{CHI} = 10.2;
$RS{206254}{SEA} = 3.2;
$RS{206254}{NYC} = 11.2;
$RS{206254}{LAX} = 20.2;
$RS{206254}{CHI} = 15.2;
####SET 2
$RS{202211}{SEA}{plan_intel} = .2;
$RS{202211}{NYC}{plan_athlon} = 2;
$RS{202211}{LAX}{plan_duron} = 3;
$RS{202211}{CHI}{plan_pentium} = 2.5;
$RS{202200}{SEA}{plan_intel} =200;
$RS{202200}{NYC}{plan_athlon} = 20;
$RS{202200}{LAX}{plan_duron} =50;
$RS{202200}{CHI}{plan_pentium} = 100;
#### CODE ###
print "works for SET 1\n";
foreach $npanxx (sort keys %RS){
for $node (sort {$RS{$npanxx}{$a} <=> $RS{$npanxx}{$b}} keys %{
$RS{$npanxx} }) {
print "$npanxx :: $node :: $RS{$npanxx}{$node}\n";
}
print "\n";
}
%hashname{$npanxx}{$node}{$plan} = cost
so that i get plans ordered by lowest to greatest cost, in the format
of:
$npanxx:: $node :: $plan :: cost
i have the solution for SET 1(see below), where the second key ($node)
completes the hash member and gives me back what i want. I just can't
solve for the higher order hash. any help would be appreciated. sample
data for SET 1 and SET 2 and code for SET 1 follows:
%RS = ();
###SET 1
$RS{206231}{SEA} = 1.2;
$RS{206231}{NYC} = 11.2;
$RS{206231}{LAX} = 4.2;
$RS{206231}{CHI} = 10.2;
$RS{206254}{SEA} = 3.2;
$RS{206254}{NYC} = 11.2;
$RS{206254}{LAX} = 20.2;
$RS{206254}{CHI} = 15.2;
####SET 2
$RS{202211}{SEA}{plan_intel} = .2;
$RS{202211}{NYC}{plan_athlon} = 2;
$RS{202211}{LAX}{plan_duron} = 3;
$RS{202211}{CHI}{plan_pentium} = 2.5;
$RS{202200}{SEA}{plan_intel} =200;
$RS{202200}{NYC}{plan_athlon} = 20;
$RS{202200}{LAX}{plan_duron} =50;
$RS{202200}{CHI}{plan_pentium} = 100;
#### CODE ###
print "works for SET 1\n";
foreach $npanxx (sort keys %RS){
for $node (sort {$RS{$npanxx}{$a} <=> $RS{$npanxx}{$b}} keys %{
$RS{$npanxx} }) {
print "$npanxx :: $node :: $RS{$npanxx}{$node}\n";
}
print "\n";
}