1 | As in other interpreters (JavaScript, e.g.), PERL allows you to execute a string using the eval function |
2 | 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: |
3 | eval('$' . $name . '[' . $index . ']') = $value; |
4 | eval returns result of evaluating its argument |
5 | In this case, you can achieve the same results with indexed hashes: |
6 | $options[$index]{$name} = $value; |
7 | using multidimensional array notation |