As in other interpreters (JavaScript, e.g.), PERL allows you to execute a string using the eval function |
Suppose you had two arrays $fred[$index] and $jim[$index] and you wanted to give them a value of $index and an ascii string $name (which could be input) taking value 'fred' or 'jim'. This can be achieved by: |
eval('$' . $name . '[' . $index . ']') = $value; |
eval returns result of evaluating its argument |
In this case, you can achieve the same results with indexed hashes: |
$options[$index]{$name} = $value; |
using multidimensional array notation |