The stupid question is the question not asked | |
PerlMonks |
Re^2: Detecting if a string is a regular expressionby LanX (Saint) |
on Jan 12, 2013 at 11:03 UTC ( [id://1013030]=note: print w/replies, xml ) | Need Help?? |
for completeness: > Of course, that doesn't test if the metachars make sense as a regex let's Perl parse Perl =)
Cheers Rolf UPDATE unfortunately not always correct:
but
UPDATE interesting, this happens because it's a run-time error ... (why?)
looks like a parser problem for me! UPDATE variable interpolation is part of the problem, a[$] is a valid pattern, as long as it's not interpolated:
UPDATE this is very reliable perl -ple ' $_ = eval "sub { 'a' =~ q\0$_\0 }" ? "OK\n" : "$@" ' to avoid problems with \0-delim consider using here-docs instead, or even a pack/unpack combination
In Section
Seekers of Perl Wisdom
|
|