Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Comment on

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

I think the ternary operator is perfectly fine when used appropriately. For example, the following snippet:

print $_ ? do { $trip = $trip ? 0 : 1; $_ } && $_ : $trip ? !( $counter % 4 ) ? do { $nexchar = pop @string +_arr; '^' eq $nexchar ? ' ' : $nex +char } || '-' : ' ' : ' ';

... is a fine example of how NOT to use it when attempting to write maintainable code. Indeed, that's pulled from a properly indented and slightly deobfuscated obfuscation. On the other hand,

my $x = $counter > 4 ? 1 : 0;

... seems like an acceptable alternative to the more verbose:

my $x; if( $counter > 4 ){ $x = 1; } else { $x = 0; }

However, this type of shorthand is often best left to be decided by your environment. If you find yourself amidst folk who are comfortable with shorthand, by all means use that as a coding standard: "Where readability is not hindered, the use of the ternary operator in assignments is encouraged". If on the other hand your environment dictates that code be more explicit, whether its due to strict maintainability requirements or the presense of junior developers as maintainers, then adjust your coding standards to suit.



--chargrill
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

In reply to Re: ?: = Obfuscation? by chargrill
in thread ?: = Obfuscation? by Melly

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 taking refuge in the Monastery: (10)
    As of 2014-10-20 11:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (75 votes), past polls