Perl 帮我看看 my %keep = map { + $_ => 1 } @files_to_keep;
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/19 17:15:55
Perl 帮我看看 my %keep = map { + $_ => 1 } @files_to_keep;
由于map{...后可接BLOCK(代码块)和EXPR(子函数、正则表达式),+是用来语法提示,告诉编译器下边的是代码块,防止编译出现语法错误.这个哈希数组应该就是保护@files_to_keep的文件,防止误删.
{ starts both hash references and blocks,so map { ...could be either the start of map BLOCK LIST or map EXPR,LIST.Because Perl doesn't look ahead for the closing } it has to take a guess at which it's dealing with based on what it finds just after the {.Usually it gets it right,but if it doesn't it won't realize something is wrong until it gets to the } and encounters the missing (or unexpected) comma.The syntax error will be reported close to the },but you'll need to change something near the { such as using a unary + to give Perl some help:
%hash = map { "\L$_" => 1 } @array # perl guesses EXPR.wrong
%hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK.right
%hash = map { ("\L$_" => 1) } @array # this also works
%hash = map { lc($_) => 1 } @array # as does this.
%hash = map +( lc($_) => 1 ),@array # this is EXPR and works!
%hash = map ( lc($_),1 ),@array # evaluates to (1,@array)
{ starts both hash references and blocks,so map { ...could be either the start of map BLOCK LIST or map EXPR,LIST.Because Perl doesn't look ahead for the closing } it has to take a guess at which it's dealing with based on what it finds just after the {.Usually it gets it right,but if it doesn't it won't realize something is wrong until it gets to the } and encounters the missing (or unexpected) comma.The syntax error will be reported close to the },but you'll need to change something near the { such as using a unary + to give Perl some help:
%hash = map { "\L$_" => 1 } @array # perl guesses EXPR.wrong
%hash = map { +"\L$_" => 1 } @array # perl guesses BLOCK.right
%hash = map { ("\L$_" => 1) } @array # this also works
%hash = map { lc($_) => 1 } @array # as does this.
%hash = map +( lc($_) => 1 ),@array # this is EXPR and works!
%hash = map ( lc($_),1 ),@array # evaluates to (1,@array)
perl 中的my (@list) =
I t was my job to keep pigs.=My job _ _ _ pigs.
perl中统计单词出现频率的一段代码,大家帮我看看我那里错了?
perl 正则表达式 my $a = "abc123xyz"; my $tmp = "123"; if ($a /abc
求这题答案,可以的话帮我看看第1题对不对(>_
帮我看看毛线团上的标签是什么意思?_
帮我看看这题如何写啊-_-#?
Map map=new HashMap();
perl 正则表达式/^\s*(.)\s*\=\s*\"(.
请问Map map=new HashMap(); 为什么是这样,而不是Map map=new Map();
perl $@
帮我看看这是什麼鱼?看看