Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://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":



  • 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 musing on the Monastery: (11)
As of 2024-04-19 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found