Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Using IF and OR, I'm sure there is a better way

by l3v3l (Monk)
on Dec 15, 2005 at 22:02 UTC ( [id://517089] : note . print w/replies, xml ) Need Help??


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.