Unless you can have gaps in your orders (eg: POPE at 0 and CARDINAL at 3 but nothing in between) you can consider your array as a hash that uses a number as key (you just access elements with $hierarchy[$pos] instead of $hierarchy{$pos}). BTW, if you are using the position to select your data rather than the name, it should be the key, not the value.
When I say that an array can be used as a hash (with keys 0..N), you can even use each on it:
And if your version of perl is not too old, use a hash slice to extract pairs of position/element:while (my ($key, $value) = each @ARGV) { print "$value: $key\n"; # The key is the position }
use Data::Dumper; print Dumper { %ARGV[0,1,3] };
Edit: so you can also get your hash with %hierarchy = reverse %ARGV[0..$#ARGV] if you want to keep the names as key.
In reply to Re: HASH Hierarchy
by Eily
in thread HASH Hierarchy
by dirtdog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |