不清楚这个shift or return是什么意思
时间:2010-10-05
来源:互联网
RT!
有点习惯这种写法但是还不知道怎么回事。求指点!!!!
#!/usr/bin/perl
use strict;
use warnings;
main(@ARGV);
sub main
{
open FH,"linesfile.txt";
my $linenum=1;
while(my $line=<FH>){
print "line $linenum is ".$line;
$linenum++;
}
close FH;
message("this");
}
sub message
{
my $m=shift or return;
print ("$m\n");
}
有点习惯这种写法但是还不知道怎么回事。求指点!!!!
#!/usr/bin/perl
use strict;
use warnings;
main(@ARGV);
sub main
{
open FH,"linesfile.txt";
my $linenum=1;
while(my $line=<FH>){
print "line $linenum is ".$line;
$linenum++;
}
close FH;
message("this");
}
sub message
{
my $m=shift or return;
print ("$m\n");
}
作者: laohuanggua 发布时间: 2010-10-05
本帖最后由 coldneverend 于 2010-10-05 11:22 编辑
perldoc
shift Shifts the first value of the array off and returns it,
shortening the array by 1 and moving everything down. If there
are no elements in the array, returns the undefined value. If
ARRAY is omitted, shifts the @_ array within the lexical scope
of subroutines and formats, and the @ARGV array outside a
subroutine and also within the lexical scopes established by the
"eval STRING", "BEGIN {}", "INIT {}", "CHECK {}", "UNITCHECK {}"
and "END {}" constructs.
See also "unshift", "push", and "pop". "shift" and "unshift" do
the same thing to the left end of an array that "pop" and "push"
do to the right end.
另外,or的用法在perlop/Logical or, Defined or, and Exclusive Or里
perldoc
shift Shifts the first value of the array off and returns it,
shortening the array by 1 and moving everything down. If there
are no elements in the array, returns the undefined value. If
ARRAY is omitted, shifts the @_ array within the lexical scope
of subroutines and formats, and the @ARGV array outside a
subroutine and also within the lexical scopes established by the
"eval STRING", "BEGIN {}", "INIT {}", "CHECK {}", "UNITCHECK {}"
and "END {}" constructs.
See also "unshift", "push", and "pop". "shift" and "unshift" do
the same thing to the left end of an array that "pop" and "push"
do to the right end.
另外,or的用法在perlop/Logical or, Defined or, and Exclusive Or里
作者: coldneverend 发布时间: 2010-10-05
和
复制代码
一样的,熟悉VBscript, Delphi的人会比较习惯or , 用C的人习惯我这种。
- shift || return
作者: wind_ch 发布时间: 2010-10-05
本帖最后由 珞水的大叔 于 2010-10-05 13:18 编辑
复制代码
相当于
复制代码
这句话是用来检查是否能获得函数的第一个输入参数,
如果能,就存放在$m中
如果不能,就return(即结束函数,并返回空)
- my $m=shift or return;
- my $m;
- if($m=shift){}else{return};
如果能,就存放在$m中
如果不能,就return(即结束函数,并返回空)
作者: 珞水的大叔 发布时间: 2010-10-05
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28