hi,,, blazar, check out this code updates:
my $test = $b; $test =~ s/\s+//g; if ($test != 0) { $test =~ s/[1-5]//; print "It is either 1,2,3,4,5\n" if ! $test and $test ne "0"; }
it may seems to be lenghty for me but if you've got shorter codes for this, then you can modify it or create a better one.
this codes prints when the $b is 1,2,3,4,5 alone... actually, it is very specific that 01,02,03,04,05, 001, etc is different from 1,2,3,4,5 (wherein it is true). i tested this to comply (as much as possible) with different end users inputs.
#!perl/bin/perl use strict; @_ = (-1000..1000, " \t\t\n 4 \t ", " \t\t\n 7 \t ", " \t\t\n 145 \t ", " \t\t\n 1 234 5 \t ", " 0 ", " 0 4 ", " \t\t 0 \n\n 3", " perl 4 \t", " \t4 perl"); for (@_) { my $test = $_; $test =~ s/\s+//g; if ($test != 0) { $test =~ s/[1-5]//; print "It is either 1,2,3,4,5\n" if ! $test and $test ne "0"; } }
you may add any additional at @_ to test.
In reply to Re^5: Quicker way to do this IF statement 1-5
by PerlPhi
in thread Quicker way to do this IF statement 1-5
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |