
perl中的函数参数传入后是存在存在数组@_中的而不是存在$_中,就算有一个元素也是如此。。。。
注意比较以下两个程序的区别,便可理解参数的含义:
1.
#!/usr/bin/perluse 5.010;sub greet{state $last;my $name=shift;if(defined $last){print "$last is here!!!\n";}else{print "no one is here...\n";}$last=$name;}greet('jim');greet('lucy'); 2.总结#!/usr/bin/perluse 5.010;sub greet{state $last;my $name=$_;if(defined $last){print "$last is here!!!\n";}else{print "no one is here...\n";}$last=$name;}greet('jim');greet('lucy');注意两者结果的区别。。。严格意义上讲第二个是错的。。。毫无意义的。
以上是内存溢出为你收集整理的perl中的函数参数全部内容,希望文章能够帮你解决perl中的函数参数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)