I would like to traverse the HASH but one by one. Not in Random ways. Any idea. For example i have hash file something like this…
our %HASH = (
'rajesh:1700' => Bangalore,
'rajesh:1730' => Delhi,
'rajesh:1770' => Ranchi,
'rajesh:1780' => Mumbai,
'rajesh:1800' => MYCITY,
'rajesh:1810' => XCF,
);
and it should print in same fashion. I tried with following but failed. Any ideas?
while ( my $gPort = each %HASH)
{
print "$gPort\n";
}
for my $gPort ( keys %HASH )
{
print "$gPort\n";
}
Given the keys in your question, a simple change to the sort comparator will give your desired output.
Note: the code above assumes all numbers in keys will occur at the same position and have the same length. For instance, a
rajesh:001775key will come out first rather than between 1770 and 1780.