quite a novel use of terminology there..

To (I think) answer your question a hash by its very nature has no concept of "order of input" as you are looking for. However there is another way. Here is one approach:

: : Much hand waving. : # initialize a couple of things my %asoc_ary=(); my @key_table=(); : : fanning the air some more sub putThingIn { my ($key,$value)=$_; push @key_table=$key; $asoc_ary{$key}=$value; } sub getThingsBack { foreach my $key(@key_table){ print $asco_ary{$key},$/; } }
As you add things to the associative array %asco_ary you are keeping track of what order they were put there in the array @key_table. The function push adds things to an array to the end of the array which is the equivilant of saying $key_array[++$#key_array]="thing";.

When you iterate through the key array and use those values as your keys into your associative array you will get your values back in the order you stored therm.


In reply to Re: Sorting hash references by blue_cowdawg
in thread Sorting hash references by diparun

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.