Syntactic Confectionery Delight | |
PerlMonks |
Re: What does the error 'Illegal division by zero' mean?by sgifford (Prior) |
on May 01, 2004 at 20:42 UTC ( [id://349690]=note: print w/replies, xml ) | Need Help?? |
Well, it looks like when the code in $code is evaluated, the length method returns 0, so $n is never incremented, so it's undef when the END block is run. For the purpose of the division, that undef is converted to 0, and there you are---division by 0.
The easiest way to fix this is to check if $n is 0, and if so don't divide by it. The hard part is figuring out what you want to do instead. :)
In Section
Seekers of Perl Wisdom
|
|