Hi
I've got a fairly chunky library that parses a big XML file full of figures. As well as grabbing the numbers out of the appropriate bits, it also calculates figures for growth percentages. Once I remembered to coerce the strings from the XML into figures (so '0.000' == 0 ), I still have to check every time before I do a division that the amount I'm dividing by isn't 0:
my $fig_1 = get_numeric_value_from_xml(...); my $fig_2 = get_numeric_value_from_xml(...); my $growth; if ( $fig1 != 0 ) { $growth = ( $fig_2 / $fig_1 * 100 ) - 100; }
If I don't check every time before I do a calculation like this, I end up dying of 'Illegal division by zero' whenever $fig_1 is zero. I was wondering if there's some way I can alter this behaviour - preferably only in the scope of this file - so that instead of dying, a division by zero simply returns undef?
TIA
Alex
In reply to Surviving 'Illegal division by zero' by ViceRaid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |