hi,

i need help with this one :) the point of this problem is that i'm looking for a way to retrace my steps. let say i have this hash that is only declared & initialized like this:

use strict; use Data::Dumper; my %hash; %hash = (key1 => [1], key2 => [1], key3 => [1]);
also let say this hash is a class variable. and thet every time the class method is called the result of its calculation is pushed into a hash, like this:
push(@{$hash{key2}},4); push(@{$hash{key3}},8); push(@{$hash{key1}},7); push(@{$hash{key2}},9); $hash{key4} = [8]; push(@{$hash{key2}},9); push(@{$hash{key3}},2);
so now i'm looking for a procedure to retrace the exact order in which i inputed the last data into my hash. in other words i would like to receive data in following order:
foreach (hash key){ my $last_one = pop(@{$hash{$_}}); print "$_ $last_one \n"; } so that rtesult is going to be: key3 2 key2 9 key4 8 key1 7 and in next iteration : key2 9 key3 8 key1 1
i don't know if you understand what am i aiming for. the data structure has to be in the hash form and only thing that interests me how to retrieve those data from that hash in revers order they were entered into the hash.

any ideas??? (i'm not looking for the actual code but just an idea :))

thank you


In reply to retrieving hash keys by baxy77bax

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.