How to print the elements of single hash in Perl without using sort builtin function in many methods?
Method 1:
%final=(9,2,1,4,7,6);
print "@{[%final]}";
Method 2:
%final=(9,2,1,4,7,6);
print %final,"\n";
Method 3:
%final=(9,2,1,4,7,6);
print "$_ $final{$_}\n" for (keys %final);
Method 4:
%final=(9,2,1,4,7,6);
while (my ($k,$v)=each %final){print "$k $v\n"}
Method 5:
%final=(9,2,1,4,7,6);
print "$_ => $final{$_}\n" for (sort keys %final);
Method 6:
%final=(9,2,1,4,7,6);
@d=%final;
print @d;
Method 7:
%final=(9,2,1,4,7,6);
print map { "$_ $final{$_}\n" } keys %final;
Method 8:
%final=(9,2,1,4,7,6);
print map {$_ . " "} %final, "\n";
Method 9:
%final=(9,2,1,4,7,6);
foreach(keys %final) { print "$_ $final{$_}\n"; }
Method 10:
%final=(9,2,1,4,7,6);
map {print "$_ $final{$_}\n"; } keys %final;
Method 11:
%final=(9,2,1,4,7,6);
print "$_ $final{$_}\n" for keys %final;
kaavannan perl blogspot
Labels: hash in perl with multiple values, kaavannan perl blogspot, perl hash, perl print hash, perl sort hash keys numerically, print hash in perl using foreach