IMHO...
1. In general, an array will be more efficient (i.e. quicker to read values from), but only if you know the element number that you are trying to access, or if you know that you want to perform a function on each element of the array - i.e.
#good print $array[3]; # faster than... print $hash{'3'}; #... this #bad for(0..$#array){ if(${$array[$_]}[0] eq 'foobar'){ print ${$array[$_]}[1]; } # slower than... } print $hash{'foobar'}; #... this
2. Err, see above...
3. Define failure... I can't think of any circumstances where you could fail to do this - the reverse is more problematic, since you would have to be prepared to handle cases where two or more array values have the same 'key'.
I have to admit that I'm not really sure what you are asking - in general the type of data-structures that you are using will dictate whether a hash or an array is more suitable. If your keys are numeric, or if there isn't really a key, then use an array, but if the keys are anything else, then a hash would make sense.
Tom Melly, pm@tomandlu.co.ukmap{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
In reply to Re: Data structure efficiency
by Melly
in thread Data structure efficiency
by shine22vn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |