Perlseeker_1 has asked for the wisdom of the Perl Monks concerning the following question:
I have formed a hash with month (mmmyy) as a key and value (numeric), and I want the output in sorted format
my code is below
I am trying print the out put as
my %data foreach my $key (sort keys %data) { print "Key - $key and b value - $data{$key}}
Hash conetent
$VAR1 = 'Dec13'; $VAR2 = '2'; $VAR3 = 'May14'; $VAR4 = '2'; $VAR5 = 'Apr14'; $VAR6 = '2'; $VAR7 = 'Mar14'; $VAR8 = '2';
but I am getting output as:
key - Apr14 and value - 2 key - Dec13 and value - 2 key - Mar14 and value - 2 key - May14 and value - 2
where I want the output in sorted format
key - Dec13 and value - 2 key - Mar14 and value - 2 key - Apr14 and value - 2 key - May14 and value - 2
Any suggestions please
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sorting keys in hash
by Laurent_R (Canon) on May 23, 2014 at 17:28 UTC | |
|
Re: sorting keys in hash
by johngg (Canon) on May 23, 2014 at 22:17 UTC | |
by AnomalousMonk (Archbishop) on May 23, 2014 at 23:27 UTC | |
by johngg (Canon) on May 24, 2014 at 15:17 UTC | |
|
Re: sorting keys in hash
by LanX (Saint) on May 23, 2014 at 16:01 UTC | |
by Perlseeker_1 (Acolyte) on May 23, 2014 at 16:08 UTC | |
by kennethk (Abbot) on May 23, 2014 at 16:17 UTC | |
by LanX (Saint) on May 23, 2014 at 16:10 UTC | |
by LanX (Saint) on May 23, 2014 at 16:50 UTC | |
by Perlseeker_1 (Acolyte) on May 23, 2014 at 16:17 UTC | |
|
Re: sorting keys in hash
by farang (Chaplain) on May 23, 2014 at 23:08 UTC | |
by AnomalousMonk (Archbishop) on May 24, 2014 at 01:16 UTC | |
|
Re: sorting keys in hash
by dbuckhal (Chaplain) on May 26, 2014 at 00:17 UTC |