Basic HTML version of Foils prepared Sept 20 97

Foil 17 Anonymous Data Structures and Subroutines

From Perl5 and Advanced Perl4 Features Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


Often one wishes to construct "unnamed" data structures or subroutines where one keeps track of them by reference as opposed to name
This is natural with subroutines which return either a data structure or subroutine
$arrayref = [1, 2, ['a', 'b', 'c'] ]; # $arrayref is a hard reference to a 2D array with 5 defined elements
  • $arrayref->[2][1] will give value 'b' as will $$arrayref[2][1]
  • $arrayref->[0][0] is 1; $arrayref->[0][1] is undef;
$secretsub = sub { print "Support ECS\n" };
executed by &$secretsub;



© 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 Apr 5 1998