Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I've said this once before. Using boolean algebra in numerical context relies on obscure implementation details while using the ternary operator relies on well-defined (and documented), designed-that-way implementation details. For that reason alone, I would not want to see this construct (not operator) in code I'd have to maintain later.

By declaring this an operator, you're making an analogy that it has some sort of precedence that can be used to avoid parenthesis - in fact, this looks more like a function in reverse (the parentheses come before the "name" of the function, which is "x!!"). So that makes it the first awkward operator we've got, even given all the extras (e.g., goatse operator, etc.).

I would instead suggest that a clearer, more maintainable version might be ($string) x ($cond ? 1 : 0). Definitely longer than your operator, but I'm not only not claiming this to be an operator (more of an idiom or pattern), but it'll be way more obvious to anyone reading it what I'm trying to do. Sure, there's still some duplication (the ?1:0 part), but not a lot more than the duplication your operator has (the x!! part).

That said, I don't find either of your original "problem" examples to be particularly onerous, and thus I may not be really appreciative of the elegance gained with some slightly obfuscated code.


In reply to Re: Secret Perl Operators: the boolean list squash operator, x!! by Tanktalus
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (4)
    As of 2014-07-13 07:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (248 votes), past polls