Hi guys, I was wondering how I could go about sorting a hash that is grown in the following manner:
my $Rec = { ORG_LEVEL_DESCRIP=>$rec->[10], GRADE=>strip_hyphen($rec->[15]), POSITION=>$rec->[2], NAME=>invert_name($rec->[16]), AGE=>convert_date_to_age(trim($rec->[17])), DATE_OF_BIRTH=>date_of_birth_cleansed($rec->[17 +]), COUNTRY=>$rec->[19], }; push @{$AG{$rec->[10]}},$Rec;
I have tried the following:
foreach my $p ( sort { $$b{GRADE} <=> $$a{GRADE}} @{$AG}) { ................. }

I get the the following output: D1 P5 P2 P3

Instead, I would like to output by letter first and then by number as illustrated below: D1 P5 P5 P4 P4 P3 P3 P2 P1 etc.

In other words, I would like to sort by this value GRADE=>strip_hyphen($rec->15) where the P5, P4, etc. are stored.
SAMPLE DATA P5 , Health Officer, M. Famzo, France, 1/1/1957 P5 , Health Officer,S. Fey, United States, 4/16/1960 P2 , Health Officer, F. Ban, France, 10/5/1966 P4 , Health Officer, J. Pino, Germany, 9/19/1948 P3 , Health Officer,G. Brown, Greece, 5/15/1974 D1 , Health Officer, J. Hill, Syria, 2/10/1962
Any ideas.

In reply to Sorting a Hash by GuiPerl

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.