perl中的函数,传参

函数参数使用特殊数组@_标明。 获取函数中的第一个参数$_[0],第二个参数为$_[1] 举例以下:web [root@localhost shell]# cat hello.pl #!/usr/bin/perl sub Average{ #获取全部传入的参数 $n = scalar(@_); $sum=0; foreach $item (@_){ $sum +=$item; }
相关文章
相关标签/搜索