in reply to a word of warning about /$pattern/

Shouldn't you anchor it, e.g.:

my $pattern = qr//; $_ = 'foo'; /\A \Q$pattern\E \z/x and print "Matched\n";

Then you don't have to worry about an empty pattern at all. You also don't have to worry about only part of the string matching the pattern.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: a word of warning about /$pattern/
by zby (Vicar) on Dec 02, 2003 at 15:43 UTC
    But he needed matching parts of the string. Actually he needed the empty pattern to match.

    I can see your answer as an automatic matching process: problem with matching empty strings => answer anchore the pattern. But this time this heuristic did not work.

    I must admit I am guilty of some automatic answers as well.