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

Re: Ternary operators

by ikegami (Pope)
on Dec 20, 2013 at 16:36 UTC ( #1067963=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        $broken->{this}    = $_ eq 'this'    ? 1 : $broken->{this};
        $broken->{that}    = $_ eq 'that'    ? 1 : $broken->{that};
        $broken->{another} = $_ eq 'another' ? 1 : $broken->{another};
    
  2. or download this
    $broken->{$_} = 1 for @list;
    
  3. or download this
    my @valid = qw( this that another );
    
    $broken->{$_} = 0 for @valid;
    $broken->{$_} = 1 for @list;
    
  4. or download this
    my %valid = map { $_ => 1 } qw( this that another );
    
    $broken->{$_} = 1 for grep $valid{$_}, @list;
    
  5. or download this
    my @valid = qw( this that another );
    my %valid = map { $_ => 1 } @valid;
    
    $broken->{$_} = 0 for @valid;
    $broken->{$_} = 1 for grep $valid{$_}, @list;
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2014-12-22 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (128 votes), past polls