Why does the first give a divide-by-zero error, while the second does not?

Thanks

Jeff_Mott
—
2013-04-06T18:10:47Z —
#2

Probably an operator precedence issue. I suspect your code is being interpreted like this:

if 14/(7 =~/\D/)

dsheroh
—
2013-04-07T07:35:57Z —
#3

Jeff_Mott said:

Probably an operator precedence issue. I suspect your code is being interpreted like this:

if 14/(7 =~/\D/)

Your suspicion is correct.

perl -e 'print "Result of division is not an integer.\
" if (14/7) =~/\\D/'

works fine.

That said, the more standard way of testing whether a value is an integer is:

perl -e 'print "Result of division is not an integer.\
" if 14/7 != int 14/7'

The intention is clearer this way, since you're explicitly testing whether the value is equal to the integer portion of the value instead of looking for the presence of non-numeric characters, which you could be doing for many other reasons.