Perl 帮我看看 my %keep = map { + $_ => 1 } @files_to_keep;

来源:学生作业帮助网 编辑:作业帮 时间:2024/12/01 10:46:26
Perl 帮我看看 my %keep = map { + $_ => 1 } @files_to_keep;
xT[kA+G4aK_5 ,^!L6'5efi,BjT,K5Զc$ -탠ɞ|;90ƒhsZL>ԛpf`pcp.V\eQ񢆜ϗRё,muwڄ,+ZhG󝸽6>qLwC:FϞ^=y=m,Ds?rn=ߏ泹u'YZWFE<|EΣdeY׻Oɛ~%x$ӱҟOV'mni+G^uw%jZ %ĕ@F /CvM$H<(rP}hW xWn.mYN?fD0+s0Y*Gh{\~f*- j !JḶCa ed7H2p% VQ}3-2kjDnQRHi@!\.tuT.JhNW7 z}")BuW2ltrl^3+6 (Ai\И FnÄWkhh40RDUݩht&8̢5qpNߙ*\&&kt-e9`oYf"'PdQdsPml

Perl 帮我看看 my %keep = map { + $_ => 1 } @files_to_keep;
Perl 帮我看看 my %keep = map { + $_ => 1 } @files_to_keep;

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)