Basic HTML version of Foils prepared Sept 20 97

Foil 75 The eval Function and Indexed Arrays of Hashes

From Tutorial on PERL Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


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



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Sep 21 1997