我是Perl的新人,在工作中遇到了这段代码,我搜索了一段时间,但没有找到答案.任何人都可以用简单的英文解释其功能吗?谢谢.
my $abc = delete $args{ 'abc' } // croak 'some information!';
解决方法
从此页面:
http://perldoc.perl.org/perlop.html#Logical-Defined-Or
Although it has no direct equivalent in C,Perl’s
//operator is related to its C-styleor. In fact,it’s exactly the same as||,except that it tests the left hand side’s definedness instead of its truth. Thus,EXPR1 // EXPR2returns the value ofEXPR1if it’s defined,otherwise,the value ofEXPR2is returned. (EXPR1is evaluated in scalar context,EXPR2in the context of//itself). Usually,this is the same result asdefined(EXPR1) ? EXPR1 : EXPR2(except that the ternary-operator form can be used as a lvalue,whileEXPR1 // EXPR2cannot). This is very useful for providing default values for variables. If you actually want to test if at least one of$aand$bis defined,usedefined($a // $b).