in reply to Re: Issue with matching regex
in thread Issue with matching regex
E.g. if you prepend this at the beginning of the script:
"abc" =~ /a/;
it suddenly starts outputting "Outside if", because /$var/ runs the last successfully matched regex if there was any (see The empty pattern //). If you don't want this behaviour (and I bet you don't), never use a match with fully dynamic contents. You can change it to /(?:$var)/, so that the pattern doesn't get empty after interpolating the variable.
Update: There probably should be a perlcritic policy forbidding a potentially empty regex match.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Issue with matching regex
by hippo (Archbishop) on Oct 20, 2022 at 08:32 UTC | |
|
Re^3: Issue with matching regex
by rsFalse (Chaplain) on Oct 20, 2022 at 11:54 UTC | |
|
Re^3: Issue with matching regex
by Athanasius (Archbishop) on Oct 20, 2022 at 14:12 UTC |