Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Ternary operators: a hinderance, not a help

by Anonymous Monk
on Aug 10, 2005 at 10:56 UTC ( #482563=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $number = $logical_test ? $value : 0;
    
  2. or download this
    my $number = $value;
       $number = 0 unless $logical_test;
    
  3. or download this
    my $number = 0;
       $number = $value if $logical_test;
    
  4. or download this
    my $number = $logical_test && $value;
    
  5. or download this
    my $number;
    if ($logical_test) {
    ...
    else {
        $number = 0;
    }
    
  6. or download this
    my $number;
    if ($logical_test) {$number = $value}
    else               {$number = 0}
    
  7. or download this
    my $number = do {if ($logical_test) {$value} else {0}};
    
  8. or download this
    my $number = $logical_test ? $value : 0;
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2020-06-03 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (27 votes). Check out past polls.

    Notices?