in reply to Re: How to identify invalid reg. expr.?
in thread How to identify invalid reg. expr.?

my $format = "foo (bar] baz"; eval '$regex = qr/$format/;'; die "ack - $@" if $@;
Danger! Danger! If $format contains a slash, that ends the regex and begins Perl again.

I think you were trying for this:

my $format = "foo (bar] baz"; eval { qr/$format/ }; die "ack - $@" if $@;
Which won't matter if it contains slashes. Almost every code that contains string-eval is broken, and almost never necessary. {grin}

-- Randal L. Schwartz, Perl hacker


update: Oh duh. Didn't see the single quotes. In which case, it's overkill, but not dangerous as-is, except that it can be misleading as to why you used single quotes and run-time eval-string instead of compile-time eval-block.