Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Re: 0 illegal modulus?

by Vynce (Friar)
on Jun 15, 2001 at 13:33 UTC ( #88732=note: print w/replies, xml ) Need Help??

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.
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://88732]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2017-05-25 19:45 GMT
Find Nodes?
    Voting Booth?