Why use a regexp? It's inefficient, and that particular regexp will fail if 1) $i contains special characters, and 2) if $i is part of another number (e.g. when $i=1 and list=(2..10), your regexp will match).
print if /^\Q$i\E$/ would fix the problem.
print if $_ eq $i is equivalent, but much more efficient.
print if $_ == $i would be even more efficient given that we're dealing with numbers here.
In reply to Re^2: looking for simple way to check scalar against array
by ikegami
in thread looking for simple way to check scalar against array
by raflach
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |