http://www.perlmonks.org?node_id=88732


in reply to Re: 0 illegal modulus?
in thread 0 illegal modulus?

well, i actually said $y*1 to force that into a numerical context. if you don't, then what if $x is 5 and $y is 'foo'?

bash-2.04$ perl -e 'print 5 % foo' Illegal modulus zero at -e line 1.
so...
bash-2.04$ perl -e '$x = 5; $y = "foo"; print ($y ? $x % $y : $x); pri +nt "\n"' Illegal modulus zero at -e line 1. bash-2.04$ perl -e '$x = 5; $y = "foo"; print ($y*1 ? $x % $y : 0); pr +int "\n"' 0 bash-2.04$ perl -e '$x = 5; $y = "foo"; print (($y*1) ? $x % $y : $x); + print "\n"' 5

as you can see, one still generates an error. as for what to return if $y is zero, i had misread your original statement.

.

Replies are listed 'Best First'.
Re: Re: Re: 0 illegal modulus?
by Anonymous Monk on Jun 15, 2001 at 14:04 UTC
    Dont use *1! Surely "foo" *is* an illegal modulus. And "0" is still false.