Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Surprised by Perl parse of ternary operator

by eyepopslikeamosquito (Chancellor)
on Dec 16, 2011 at 12:52 UTC ( #943938=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    config = ''
    fred = 42
    fred == 42 ? config = 'k1' : config = 'k2'
    print "config=#{config}\n"
    
  2. or download this
    <?php
    $config = '';
    ...
    $fred == 42 ? $config = 'k1' : $config = 'k2';
    echo "config=$config\n";
    ?>
    
  3. or download this
    #include <stdio.h>
    int main()
    ...
       printf("config=%d\n", config);
       return 0;
    }
    
  4. or download this
       fred == 42 ? (config = 1) : (config = 2);  // this works
       fred == 42 ?  config = 1  : (config = 2);  // also works
       fred == 42 ? (config = 1) : config = 2;    // syntax error
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://943938]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2015-07-28 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls