有时会看到这个的函数:
sub GetSnmpTable ($$$$) {
my $session = shift;
...}
sub GetNameTables ($$$) {
my $session = shift;
...}
这里只是显示的说明了我们要用多少的参数。
所有的参数会被存入@_数组中。如果想把数组或hash做为参数,且要做为一个整体使用。the arguments will be automatically stored in variable @_. can be used $_[0], $_[1]....
如下:
- #!/usr/bin/perl
-
#
-
use strict;
-
-
my $sum = &add_two_num((1,2));
-
print $sum;
-
my @ary = ("this", "is");
-
my %h = ("name"=>'lu', "age"=>23);
-
&print_args(3, \@ary, \%h );
-
-
sub add_two_num($$$){
-
my $num1 = shift;
-
my $num2 = shift;
-
-
return $num1 + $num2;
-
}
-
-
sub print_args($\@\%){
-
my ($s, $t, $h) = @_;
-
foreach my $k (keys %$h){
-
print $k, "=>", $h{$k};
-
}
-
print @$t,"\n", %$h;
-
}
阅读(627) | 评论(0) | 转发(0) |