Tuesday, September 4, 2012

How can you sort the keys of a Hash alphabetically?

#!/usr/bin/perl
   
%FM = ( 'Radio City' => 91.1,
              'Big FM' => 92.7,
              'Red FM' => 93.5,
              'Radio One' => 94.3,
              'Radio Mirchi' => 98.3,
              'Fever' => 104.0,
              'Oye FM' => 104.8,
              'FM Rainbow' => 107.1,
              'FM Gold' => 100.7);

foreach $station (sort keys %FM)
{
    print "$station is $FM{$station} MHz.\n";
}

No comments :