in reply to one-line conditional print?
sub pl { $count == 1 ? 0 :1 } # check plural my @s=("","s"); my @are=qw/is are/; for $count (1..3) { print "There $are[pl] $count piece$s[pl] of pizza left!\n"; }
gives
There is 1 piece of pizza left! There are 2 pieces of pizza left! There are 3 pieces of pizza left!
This approach is quite flexible if you need to handle irregular plurals like @children=qw(child children)
HTH!
Cheers Rolf
PS: if you wanna get rid of the pl() function you could use tied arrays evaluating index $count.
UPDATE: cleaned code...
1) yes eval is not the only backdoor for code injection ...
|
|---|