Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!cbmvax!schmid From: schmid@spica.cbmvax.cbm.commodore.com (Bob Schmid) Newsgroups: comp.lang.perl Subject: Efficiency of eval (emulating multidimentional arrays) Message-ID: <13041@cbmvax.commodore.com> Date: 5 Jul 90 01:35:42 GMT Sender: news@cbmvax.commodore.com Distribution: comp.lang.perl Organization: /user/schmid/.organization Lines: 36 I'm using eval to create a large number of associative arrays based on different, variable dependent, names. Eval seems to take about 1 millisecond extra per eval on a Sparcstation1 compared with explicitly typing out the variable names. This seems to me like a good tradeoff between execution speed and manageable coding complexity (I really need that extra array index!). Any comments on eval efficiency or better ways to skin the cat will be most appreciated.... The following sample program uses integer indexing. I usually use strings (hence the need for associative arrays). for $cell (1..100) { for $i (1..100) { eval("\$junk_$cell{\$i} = \$i"); } } for $cell (1..100) { while (($key, $val) = eval("each \%junk_$cell")) { print "\$key=$key \$val=$val"; } } ------------------------------------------------------ R. Schmid Commodore Technology 1200 Wilson Drive West Chester, PA 19380 ------------------------------------------------------