#!/usr/bin/perl sub t { print "in t\n"; print "@_\n"; &s; } sub s { print "in s\n"; print "@_\n"; } t(1,2); print "out\n"; print "@_\n";
输出:
in t 1 2 in s 1 2 out
如您所见,当没有参数通过时,输出1 2.这是一个功能还是一个bug?
测试版本为5.8.8.
解决方法
使用& NAME调用子程序;语法使当前@_可见.这在
perlsub记录:
If a subroutine is called using the
&
form,the argument list is optional,and if omitted,no@_
array is set up for the subroutine: the@_
array at the time of the call is visible to subroutine instead. This is an efficiency mechanism that new users may wish to avoid.
所以这绝对是一个功能.