It is just a personal preference, but i would make a little sub that would package away the addition, and do the input checking (i.e. remove any non-digits, warn if the number is -1000_000, or any other of the situations pointed out) and provide helpful errors if anything is bad.
use warnings; ## or die! use strict; ## seriously - don't anger the gods use diagnostics; ## but if you do, make them tell you why (patiently) +... if (my $big_int = big_int('101_dalmations') ){ ... it was OK so go ahead and play ... } else { ... no need for this bit, error messages already generated! ... ... maybe you want to do something else though? ... } ### SUBS ### sub big_int{ my $input = shift; ## check for any source of errors if ( $input =~ /\D/ ){ ## non-digits - argh! warn "$input contains non digits\n"; return 0; } elsif (... something else ...){ ... } return ($input + 1000_000); }
It just means that what you are actually trying to achieve (make a big int) remains clear, while also handling the errors nicely if they don't conform etc...
Just MHO though...
In reply to Re: Style and warnings
by BioLion
in thread Style and warnings
by api
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |