Firstly, there's lots of useful code dealing with this already on the monastery. Type sorting hash into the search box at the top of the page to find it.

The first potential problem is that your hash values can't contain the ; character. See perlfunc:split (specifically, its LIMIT argument) to find out why. Basically, unless you specify the number of fields split should return, it will create any array using every ; it finds as a delimeter.

Also, you're assigning the key to be the value at $callhash{$key} = $key. Are you sure you don't want $callhash{$key} = $value instead?

Finally, think about how scoping works. At the top of your code, you're declaring $key and $value to be empty strings. Then within your while loop you declare new variables, but they are only valid within the scope of that loop. So, when you try to print $value within your foreach loop, you're outputting the empty string you declared at the top of the code. Here, you probably want to remove $value.

Also, I assume you're using strict and warnings (or -w) earlier on in your code. Good luck!

Update: I need to learn to type faster. There weren't any replies when I started writing this!


In reply to Re: Hash sorting by tomhukins
in thread Hash sorting by jamen

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.