in reply to Swapping Two Hash Values
Yup, you're correct, you can't have duplicate keys.. and you haven't.. try this..
sub display { print '-' x 30,"\n"; foreach my $key (sort (keys (%hash))) { printf("%12s is now number %d\n",$hash{$key},$key); } print '-' x 30,"\n"; foreach my $key (sort keys %hash) { print "$key = $hash{$key}\n"; } print '-' x 30,"\n"; } __END__ prints: ------------------------------ angel is now number 1 buffy is now number 2 cordelia is now number 3 dawn is now number 4 ethan is now number 5 is now number 5 faith is now number 6 giles is now number 7 ------------------------------ 1 = angel 2 = buffy 3 = cordelia 4 = dawn 5 = ethan 54 = 6 = faith 7 = giles ------------------------------
cheers,
J
|
|---|