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


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

in Table To:


© 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