Hi Experts,

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


In reply to sorting keys in hash by Perlseeker_1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.