perlmeditation
nella
Upon writing
<code>$a % 0</code>
I am told that 0 is an illegal modulus.<br>
<br>
However, according to "Concrete Mathematics: A Foundation for Computer Science", by Graham, Knuth (yes, <i>that</i> Knuth) and Patashnik 2nd ed. (page 82)
<blockquote>
x mod y is defined as x - y{x/y} (where {} is floor) for y!=0, and x mod 0 is defined to be x.
</blockquote>
This definition is justified; it preserves the property that x mod y always differs from x by a multiple of y, and makes sense if you think of it this way: x mod y means "map y to 0", so if y already is 0, then there is nothing to do, and x mod 0 should be congruent to x.<br>
<br>
Yes, I know that division by 0 is a Bad Thing, but technically we are not dividing, we are defining the mod operator.<br>
<br>
So this is more of a rant than a question, but it annoys me to lose functionality from one of my favourite operators in such an amusing language as Perl.