Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: a word of warning about /$pattern/

by hardburn (Abbot)
on Dec 02, 2003 at 14:48 UTC ( [id://311630]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://311630]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found