Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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}

In reply to Re^2: Secret Perl Operators: the boolean list squash operator, x!! by shmem
in thread Secret Perl Operators: the boolean list squash operator, x!! by Aristotle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-20 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found