in reply to If /Else Structure when If is used in latter part of a line.
You can't. Just use the normal expression :
foreach (@input) { if( exists $list{ $_ } ) { push @name_nums, $list{$_}; } else { push @name_names, $_; } }
TMTOWTDI :
foreach my $input (@input ) { push @name_nums, ( exists $list{ $input } ? $list{ $input } : $in +put ); } ## following will not work if $list{ $input } can be 0 or undef, ## but here's another way foreach my $input ( @input ) { push @name_nums, ( $list{ $input } || $input ); }
|
|---|