http://www.perlmonks.org?node_id=564887


in reply to Re: Secret Perl Operators: the boolean list squash operator, x!!
in thread Secret Perl Operators: the boolean list squash operator, x!!

The x!! "operator" is a composite operator as the (babycart | supermarket trolley | pram) "operator" @{[]}, which isn't an operator either.

It's called an operator here just for fun.

Next, for cleanliness, it should be written as x !! EXPR. Ok, you could write this as x (!(!(EXPR))) if you don't trust precedence not verbosely stated by parens. Oh wait... list context? ;-)

Then, LIST x NUMBER is a well-defined construct (see perlop). And !! as a double negation isn't that hard to grasp, either.

Obscure implementation details? I can't see them here more than in any other perl construct. Perl is a langage with many obscure implementation details, many if not most of them are about context.

One strength of perl (which I love) is the possibility to use idiomatic constructs which rely on well defined features of the language, which, of course, must be understood to use and -- to understand them. Once you have grokked double negation and list repitition via x, the construct () x !! EXPR is cheesecake to grasp at a glance.

That said, I find the LIST x DOUBLE_NEGATION EXPR much more readable than the ternary operator in the context given by the OP, because it comprises less noise, that is, less chars necessary to grok to form a picture of what is meant in my mind. Another major benefit of it is that the construct () x !! EXPR keeps you aware of what x does to a list, and what unary ! is about (and that, if as a maintainer you don't grok them, you look up the docs).

update: read Re^5: One out of three ain't bad (order). While you are correct in that addition, subtraction, multiplication, division make no sense in boolean algebra, perl doesn't care, because the scope of bolean algebra just ends after evaluating !!. Would you prefer a typecast instead?

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}