On Sat, May 1, 2010 at 7:45 AM, Philip Potter <philip.g.pot...@gmail.com> wrote: > 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. >
And there's the rub: "number" ne "integer". % is fine if you're only interested in integers, but if you want to compare other numbers use fmod() from POSIX.pm: perl -MPOSIX -wle 'print POSIX::fmod(35, 17.5)' It's considerably slower than %, but it gets the job done. HTH, -- jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/