Hi

I am trying to create a structure which holds names and values which will later be translated into linux environment variables.

For example: $hash{VAR1}="me" will later turn into an environment variable called $VAR1 which value will be "me".

However, i would like to do it in a more sophisticated way where each variable has a priority. This way, i can decide that a certain variable will be created before the other.

I would like my structure to look something like:

$hash{10}{VAR1}="me" $hash{20}{VAR2}="you"
In this way, $VAR1 will be created before $VAR2.

My problem here is efficiany: during the program, i would like to run queries on this structure so i can know the value of a variable and it's priority.

For example: if my structure would be built in the way i described above, i could just run a statement like  if($hash{20}) { ... } to check if a priority i have given already exists, however, if i wanted to know the value of a variable, i would have to run a  foreach loop which would go through the whole hash inorder to find it.

If i build the structure as following:

$hash{VAR1}{priority}{value1}

It would be easier for me to get the value of the variable, or check if it already exists, however, if i would like to check if a priority exists, or if one priority is lower than another, i would have to go through the whole hash again to check it.

What would be your suggestion for building such a structure ?

Thanks

20040718 Janitored by Corion: Converted TR tags to P tags


In reply to a hash with priority by meirgold

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.