September 2002
Intermediate to advanced
496 pages
10h
English
In Perl, when a subroutine is invoked, the arguments to the subroutine are collected in a special array named @_. This array comes into existence only when a subroutine is invoked. Inside the subroutine, if you need to fetch the individual elements of @_, you can reference them as $_[0], $_[1], and so on. Here is a version of the header subroutine, which allows arguments to be passed to it. See the folder Org2.
% type org2.pl # # org2.pl # sub header { print "==============\n"; print "$_[0]\n"; print "$_[1], "; print "$_[2].\n"; print "==============\n"; } header("/training/etc", "Columbia", "MD"); header("Toy Factory", "Miami", "FL"); % perl org2.pl ============== /training/etc Columbia, MD. ============== ============== ...Read now
Unlock full access