@_和$_的问题
程序代码:
#!/usr/bin/perl -w my @names = qw /petty ali amily alice /; print "@names\n"; change(@names); print @names; sub change { my(@source) = @_; print "\@_:@_\n"; print "\$_:$_\n"; # $_[1]="hello world"; # @_[1]="hello world"; }
被注释掉的两行如果,如果调用@_[1]=...,就会出现Scalar value @_[1] better written as $_[1] at ./a.pl line 13.
如果调用$_[1]=...,之前调用print "\$_:$_\n"会有提示Use of uninitialized value $_ in concatenation (.) or string at ./a.pl line 11.,$_的值输出是空。但是结果确又确实是修改了,不知道这个是如何处理的。