In addition to the very helpful comments you've already received, I'd like to point out that, as a rule, I'd "metaquote" the scalar variable in the regex, just in case it contains characters (e.g. +) that otherwise would have special meaning in a regular expression:
m|\Q$input|o
For example:
The first match fails because it tries to match one or more 5s immediately followed by a 2. That's because the + is being interpreted as a regexp quantifier, not a literal character.my $string = '15+2=17'; my $input = '5+2'; $string =~ m|$input|o; # Fails $string =~ m|\Q$input|o; # Succeeds
See the aforementioned perlre, and while you're at it also check out quotemeta.
the lowliest monk
In reply to Re: Perl regular expression question
by tlm
in thread Perl regular expression question
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |