在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
codehere(); #void context $c=codehere(); #scalar context ($l)=codehere(); #list context @a=codehere(); #list context %h=codehere(); #list context print codehere(); #list context foreach (codehere()) { #list context if ( 1 <= codehere() ) { #scalar context
When you do something along the lines of this: $a=( codehere(),codehere() ); then the $a= forces the right side into scalar context since perl can see you don't want a list so in scalar context, the right side isn't treated as a list but as a statement group. Thus, "," is an operator that forces void context on it's left-hand-side and passes on the whatever context it is in to it's right-hand-side. Since you strung together a series of values like this: $a = ( 2, 3, 4, 5, 6 ); the first four numbers are in void context and only the last item in the series is in scalar context. Thus your statement could be rewritten: 2; 3; 4; 5; $a = 6; And, bam!, from that you can see there are 4 constants in void context. Run either of those with perl -we on the command line and enjoy seeing the 4 warnings pop-up. BTW, $a = ( 1, 5 ); pulls no error. =) It seems that perl and in fact Perl treat 1; special.
|
请发表评论