in reply to Style and warnings
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...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Style and warnings
by JavaFan (Canon) on Aug 18, 2009 at 15:43 UTC | |
by BioLion (Curate) on Aug 18, 2009 at 17:40 UTC | |
by JavaFan (Canon) on Aug 18, 2009 at 20:48 UTC | |
by BioLion (Curate) on Aug 19, 2009 at 07:33 UTC | |
|
Re^2: Style and warnings
by api (Initiate) on Aug 18, 2009 at 17:39 UTC |