in reply to Short and easy way to write if...elsif syntax
my @array = ("linux", "milinus","Windows","windows","Linux"); foreach (@array){ if (/((linux|Windows))/i){ print "This is $1 VM" . "\n" } else { print "no idea" . "\n" } }
... mmmh, or even:
foreach (@array){/((linux|Windows))/i ? print "This is $1 VM\n": print "no idea\n"}(in fact you don't need an array for this)
print "THIS is $^O\n";Therefore you could still eliminate two or three characters:
foreach (@array){/(($^O|Windows))/i ? print "This is $1 VM\n": print "no idea\n"}
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Short and easy way to write if...elsif syntax
by slayedbylucifer (Scribe) on Aug 27, 2012 at 16:58 UTC |
In Section
Seekers of Perl Wisdom