Basic HTML version of Foils prepared April 16,1996

Foil 21 There really are only 1D Arrays and Hashs! - II

From Perl5 and Advanced Perl4 Features Computational Science for Information Age Course CPS616 Material -- April 16,1996. by Geoffrey C. Fox


continuing from previous foil
  • $LoL2D[$i] = \@list; # does create a 2D array but \@list is same location each time and so $LoL2D[$i][$j] will give same answer whatever $i chosen with final @list returned being accessed each time
  • $LoL2D[$i] = [ @list ]; # finally creates intended 2D array as array constructor [ ] will create a fresh reference for each $i
} # End for $i (1..10)
  • my(@list) = somefunc($i); # my creates a fresh instance each time
  • $LoL2D[$i] = \@list; # also works but is perhaps less clear
Note my() can occur as here inside any block { } and not just at start of subroutine and defines variables local to block



© 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