Bill McCormick wrote: > On 2/25/2014 4:30 PM, Bill McCormick wrote: >> What would be the perl'ish way using map or some other sugar to check if >> a list of values meet some criteria? Instead of doing something like >> >> my @issues = qq(123,456,a45); >> my $max = 999; >> >> for (@issues) { >> die if $_ < 0 or $_ > $max; >> } >> > Revision: > > for(@issues) { > print "issue=[$_]\n"; > die "$_ not a number\n" if $_ ne $_+0; > die "$_ not in range\n" if $_ < 0 || $_ > $max; > } > > > > ---
Are you sure you want to die the first time an "issue" doesn't fall within the requirements? use Number::Range; use Scalar::Util qw(looks_like_number); my @issues = (123,456,'a45'); my $range = Number::Range->new("0..999"); for my $value (@issues) { print "issue=[$value]\n"; unless (looks_like_number($value) and $range->inrange($value)) { warn "Issue '$value' is either not a number or is out out of range\n"; } } --- Ron -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/