In Control flow§
See primary documentation in context for unless
When you get sick of typing "if not (X)" you may use unless
to invert the sense of a conditional statement. You cannot use else
or elsif
with unless
because that ends up getting confusing. Other than those two differences unless
works the same as if:
unless 1 ; # does not say anything, since 1 is true
unless 1 "1 is false".say ; # syntax error, missing block
unless 0 ; # says "0 is false"
unless 42.say and 1 ; # says "42" but does not say "43"43.say unless 42.say and 0; # says "42" and then says "43"43.say unless 42.say and 1; # says "42" but does not say "43"= 1; unless 0 ; # says "1"= 1; unless 0 -> ; # says "0"= 1; unless False -> ; # says "False"my = 0; say (1, (unless 0 ), 3, ); # says "(1 2 3 42)"my = 0; say (1, (unless 1 ), 3, ); # says "(1 3 0)"