in reply to comparison with bitwise operators
Update: a 4th way involves the smart match operatoruse warnings; use strict; use List::MoreUtils qw (any); my $var = 3; if (grep { $var == $_ } 2, 3) { print "in list\n"; } else { print "not in list\n"; } if (any { $var == $_ } 2, 3) { print "in list\n"; } else { print "not in list\n"; } my %vals = map {$_ => 1} 2, 3; if (exists $vals{$var}) { print "in list\n"; } else { print "not in list\n"; } __END__ in list in list in list
use 5.010; if ($var ~~ [2, 3]) { print "in list\n"; } else { print "not in list\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: comparison with bitwise operators
by LanX (Saint) on Jan 13, 2011 at 22:23 UTC | |
by toolic (Bishop) on Jan 14, 2011 at 14:11 UTC | |
|
Re^2: comparison with bitwise operators
by alextor (Novice) on Jan 13, 2011 at 22:00 UTC |