How to swap the key,value pairs.in any Associative Array?
For Example
%mani = qw{ one-->22 ,two -->44 , three->33 ,four-> 55 }
it should be
%mani = qw{ 22-> one , 44->two, 33-> three ,55->four }
kindly write a program for that.
Swap Hash Values!
Page 1 of 13 Replies - 4743 Views - Last Post: 18 March 2008 - 01:26 PM
Replies To: Swap Hash Values!
#2
Re: Swap Hash Values!
Posted 16 March 2008 - 11:29 AM
Post the code you have written to try and work out this extremely simple problem.
#3
Re: Swap Hash Values!
Posted 18 March 2008 - 01:21 AM
my %hash=('1'=>'2','4'=>'5');
my %hash2;
while (($key, $value) = each %hash) {
$hash2{$value}=$key;
}
%hash=%hash2;
foreach $key(sort keys %hash) {
print "$key:=>$hash{$key}\n";
}
I dont know this is best way to do swap.I hope it will help you.
Regards
Rajiv
my %hash2;
while (($key, $value) = each %hash) {
$hash2{$value}=$key;
}
%hash=%hash2;
foreach $key(sort keys %hash) {
print "$key:=>$hash{$key}\n";
}
I dont know this is best way to do swap.I hope it will help you.
Regards
Rajiv
#4
Re: Swap Hash Values!
Posted 18 March 2008 - 01:26 PM
Thats it, just post the answer to their school/class work for them. My goodness Rajiv, you should know better than that, you look like a smart guy.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|