in reply to A mod2 Machine.
compares withmy $n = 534587; print "even\n" if($n % 2 == 0); # modulo operator of possibly a flo +at or possibly an integer (*)
(*) perlop: Integer-Arithmetic saysuse integer; my $n = 534587; print "even\n" if($n & 1 == 0); # checking LSB with Bitwise And on +an integer
compares with:my $n = "534587"; print "even\n" if($n =~ /[02468]$/); # reg exp
my $n = "534587"; my $c = substr($n, -1, 1); # last char print "even\n" if ( ($c == '0') || ($c == '2') || ($c == '4') || ($c = += '6') || ($c == '8') ); # no regexp
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A mod2 Machine.
by choroba (Cardinal) on Jul 10, 2013 at 11:35 UTC | |
by code-ninja (Scribe) on Jul 10, 2013 at 17:30 UTC | |
by zork42 (Monk) on Jul 13, 2013 at 09:26 UTC |