Is a short circuit operator?

In the Smart Matching Details section of perlsyn:

Smart match operator short circuit whenever possible.

Does it ~~have something in common with short circuit operators ( &&, ||etc.)?

+3
source share
2 answers

The meaning of the short circuit here is that the evaluation will be stopped as soon as a logical result is established.

perl -E "@x=qw/a b c d/; for (qw/b w/) { say qq($_ - ), $_ ~~ @x ? q(ja) : q(nein) }"

b Perl , b @x. , grep, , , , , , , .

perl -E "@x=qw/a b c/; for (qw/b d/) { say qq($_ - ), scalar grep $_, @x ? q(ja) : q(nein) }"
+4

, , , ~~ , .

, sub x { ... }; my %h; ...; %h ~~ \&x true, x true %h; false, false , . &&.

, /foo/ ~~ %h true, , ; ||.

+4

All Articles