Efficiency in this case depends on a couple of things:
- a. How many different variable names are there going to be?
- b. How many different priority levels are there going to be?
- c. Do they have (m)any "gaps" - i.e. levels are 10, 15, 20, 30 ... or 1, 2, 3, 4...
- d. How many checks on existance of a priority level are there going to be?
- e. How many checks on on existance of a variable name are there here going to be?
- f. Are there multiple uses of the same priority level or variable name?
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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.