in reply to Re: extract numbers from unformatted text strings
in thread extract numbers from unformatted text strings
Nice, but don't forget the first rule of a capturing m// - test for success before using $1...
while (<DATA>) { next unless m/(\d+)\D+(\d+)/; # or warn && next, or die $min = $1 if $1 < $min; $max = $2 if $2 > $max; }
Also, rather than imposing an artificial limit on min (and max), what about addind a definedness check?
$min = $1 if ( ! defined( $min ) || ( $1 < $min ) ); $max = $2 if ( ! defined( $max ) || ( $1 > $max ) );
I'll grant that the since this doesn't handle negative numbers (yet) anyway, max is likely fine the way it is.
|
|---|