Efficiency in this case depends on a couple of things:

You can assume the efficiency doesn't really matter as long as a, b, d, and e are "low" for some value of low.

If you have lots of lookups on priority, put priority first : $hash{$priority}->{$name} - you can use an array if you have a "continuous" list of priorities in this case: $array[$priority]->{$name}.

If you have lots of lookups on name you can put name first: $hash{$name}->{$priority}.

If you have lots of lookups on both name and priority and less "inserts" make 2 indexes: $names{$name}->{$priority} and $priorities{$priority}->{$name}.

If you only use 1 priority per name and vice versa, you can collapse them so it will be faster to look up:

# for named lookup $names{$name} = { priority => $priority, value => $value }; # for priority lookup $priorities{$priority} = { name => $name, value => $value };

As you can see, there are quite a lot of options.

note that, on Unix, setting ENV will only affect programs exec'd from the current program (including system(), backticks etc.), NOT the "calling" environment (shell).

Updated: slightly better list layout


In reply to Re: a hash with priority by Joost
in thread 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.