in reply to Quicker way to do this IF statement 1-5

You mean
if ($b == 1 || $b == 2 || $b == 3 || $b == 4 || $b == 5) { print "\$b is a number and is either 1, 2, 3, 4, or 5."; } else { print "\$b has to be a number and to be either 1, 2, 3, 4, or 5."; }

I'd write

if ($b =~ /^\d$/ and $b > 0 and $b < 6) { ... }

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: Quicker way to do this IF statement 1-5
by GrandFather (Saint) on May 20, 2007 at 19:18 UTC

    If you can't use the character set [1-5] in the regex, at least use the actual constants for comparison rather then a different bunch:

    if ($b =~ /^\d$/ and $b >= 1 and $b <= 5) { ... }

    DWIM is Perl's answer to Gödel