Passing Arguments to Subroutines
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. ============== ============== ...
Get Programming PERL in the .NET Environment now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.