Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

.


Comment on Re: Re: 0 illegal modulus?
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://88732]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2015-07-30 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls