http://qs1969.pair.com?node_id=517089


in reply to Re: Using IF and OR, I'm sure there is a better way
in thread Using IF and OR, I'm sure there is a better way

these will work even if it is a double digit in $var (ie: 1 and 10 will both succeed for the first example) but if you only want one digit in range maybe something like:
print $& if $var =~ /^[1-3]$/;
or ... better yet ... if you are going to be doing this alot and with strings as well as digits ...
sub look_into { my $archetype= shift; eval 'sub { $_[0] =~ /$archetype/o; }' } my $is_text_am_too_red = look_into q/\b(am|too|red)\b/; my $single_digit_in_range = look_into q/^[1-5]$/; my $double_digit_in_set = look_into q/^[5-7][49]$/; # etc. if($is_text_am_too_red ->($_)){ print "get some sleep!" } if($single_digit_in_range ->($_)){ print "single digit in range!" } if($double_digit_in_set ->($_)){ print "double digit in set!" } #etc.