in reply to special characters in regexp
First, avoid using $a and $b; they're special.
If you are intending for $regexPattern to be a user supplied regex that may contain errors, then perhaps you want to *eval* the regex match and trap said errors.
my $matched; my $contender = 'foo'; my $regexPattern = '+foo'; #won't work eval { $matched = $contender =~ /$regexPattern/ }; warn $@ if $@; print "Hey, did I survive the error? Yay!\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: special characters in regexp
by JavaFan (Canon) on Jun 22, 2010 at 03:45 UTC |