Basic HTML version of Foils prepared March 30 97

Foil 81 The eval Function and Indexed Arrays of Associative Arrays

From PERL4 Tutorial for CPS616 Computational Science for Information Age Course CPS616 -- February 1995. by Geoffrey C. Fox


1 As in many interpreters, PERL allows you to generate a line from the interpreter using an eval function (JavaScript is similar)
2 Suppose you had two arrays $fred[$index] and $jim[$index] and you wanted to load them given value of $index and an ascii string $name (which could have been read in) taking value 'fred' or 'jim'. This can be achieved by:
3 eval('$' . $name . '[' . $index . ']') = $value;
4 eval returns result of evaluating(executing) argument as PERL script and continues
5 In this case, you can achieve the same results with indexed associative arrays:
6 $options[$index]{$name} = $value;
7 using the nultidimensional array notation introduced in PERL5

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 Sat Sep 6 1997