On 1 May 2010 12:15, Paul <opensou...@unixoses.com> wrote:
> Hello all.  How can I test to see if a number is divisible by say, 40?
> Thanks.

Use the modulo operator %. Given integers $x and $y, the expression $x
% $y gives the remainder when $x is divided by $y. As a result, if
(and only if) $x is exactly divisible by $y, $x % $y is equal to 0.

#!perl
use 5.010; # for 'say'

say 5 % 2;
say 6 % 2;
say 7 % 2;

say 79 % 40;
say 80 % 40;
say 81 % 40;

For more information, see
http://perldoc.perl.org/perlop.html#Multiplicative-Operators

Phil

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to