Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
say you wanted to do
   $condition ? $a=2 : $b=3
would
   ($condition) ? ($a=2) : ($b=3)
then be the correct/advisible way to do it?
It would be one way to do it with a ternary operator. Another way is shown below. Both are correct (i.e., compile without error). Which is 'advisable' depends on circumstances; I tend to prefer the ternary form below, but
   if ($cond) { $a = 2 } else { $b = 3 }
seems the clearest and most advisable of all.
>perl -wMstrict -le "my $cond = shift; $a = $b = 99; ($cond ? $a : $b) = ($cond ? 2 : 3); print qq{a $a b $b}; " 0 a 99 b 3 >perl -wMstrict -le "my $cond = shift; $a = $b = 99; ($cond ? $a : $b) = ($cond ? 2 : 3); print qq{a $a b $b}; " 1 a 2 b 99

In reply to Re^2: Why does the Perl conditional operator not do what I expect? by AnomalousMonk
in thread Why does the Perl conditional operator not do what I expect? by vinoth.ree

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 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? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2021-12-02 02:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (16 votes). Check out past polls.

    Notices?