Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
The first example uses assignment before the ? operator so that the parts of the RHS of the assignment will be executed predictably according to the condition to the left of the '?'.

The second example does not do any assigning before the ?. It's true that perl will execute an 'or' or 'and' in such a non-assignment context, but (IMHO) that feature cannot be assumed for all operators and apparently not '?'.

Hope this helps.


Update: Precedence (offered later) is a tempting explanation but I think it is merely executing both assignments in the order left to right because without an assignment to drive the ?, the parser is forced to execute the lot and then go nowhere with the ? because it has no documented reason to

- but I do agree with using brackets to control the precedence or in this case, wake it up!

One world, one people

In reply to Re: Question about ternary condition by anonymized user 468275
in thread Question about ternary condition by Tomtom

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?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2022-12-05 09:10 GMT
Find Nodes?
    Voting Booth?

    No recent polls found