传递给子程序的参数列表放在一个名为@_的列表中。
#!/usr/bin/perl
# Fig 6.5: fig06_05.pl
# Demonstrating a subroutine that receives arguments.
displayArguments( "Sam", "Jones", 2, 15, 73, 2.79 );
# output the subroutine arguments using special variable @_
sub displayArguments
{
# the following statement displays all the arguments
print "All arguments: @_\n";
# the following loop displays each individual argument
for ( $i = 0; $i < @_; ++$i ) {
print "Argument $i: $_[ $i ]\n";
}
$i = 0;
for(@_) {
print "\$_ is: $_\n";
print "\$_[\$i] is: $_[$i]\n";
++$i;
}
}
阅读(1557) | 评论(0) | 转发(0) |