in reply to Re: mod function
in thread mod function

Don't forget...

unless ($y % 3) { }

I think that, for the most part, I prefer the explicitness of if ($y % 3 == 0) { } though.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Re: mod function
by boo_radley (Parson) on Nov 12, 2002 at 19:12 UTC
    I'm curious (genuinely curious, not picking a fight) as to why if (...) is more explicit than unless (...)? Is it because if is more ubiquitous?

      To me the advantage of:

      if ($y % 3 == 0) { }

      is that you are explicitly stating that you are testing for a modulus being zero.

      With:

      unless ($y % 3) { }

      you are saying you are interested in Perl's idea of the statement's truth/falsehood - which is a subtly different concept.