Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: 0 illegal modulus?

by nella (Novice)
on Jun 12, 2001 at 01:04 UTC ( #87652=note: print w/ replies, xml ) Need Help??


in reply to 0 illegal modulus?

I think that should be:

$ans = $y ? %x % $y : $x

Yes, this would work (but it still seems hackish). Thanks for the advice.


Comment on Re: 0 illegal modulus?
Download Code
Re: Re: 0 illegal modulus?
by Vynce (Friar) on Jun 15, 2001 at 13:33 UTC

    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.

    .
      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://87652]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2015-07-05 17:45 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 (67 votes), past polls