Basic HTML version of Foils prepared April 16,1996

Foil 30 Some Remarks about Subroutines - VII -- AUTOLOAD

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


One can define a default function AUTOLOAD to resolve unsatisfied subroutine references in a gibven (set of) packages.
You set up AUTOLOAD to deal with this case in whatever way you want!
AUTOLOAD is passed arguments that went to called subroutine and name of unsatisfied external is in variable $AUTOLOAD
sub AUTOLOAD { # Call UNIX for unsatisfied externals
  • my $program = $AUTOLOAD;
  • $program =~ s/.*:://; # remove any package precursors
  • system($program, @_);
}
date(); # will now just be executed correctly by above AUTOLOAD



© 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