On 1/9/06, Tom Allison <[EMAIL PROTECTED]> wrote:
> Tom Allison wrote:

> $string =~ /(?:(A|B))/   WORKS!!!!
> $string =~ m|(?:(A|B))|  DOES NOT WORK
> $string =~ m%(?:http://)%;  ALSO WORKS....

The m// operator is a quoting construct. The general rule is that,
after the initial m, you may use any punctuation mark for the start
and end of your pattern match. If you use a left-mark to start, the
end is the corresponding right-mark; if the mark isn't one of these
four < ( [ { then the end is the same as the start. If you wish to use
the end mark inside the quoted section, you must backslash it.

Or, better yet, choose a delimiter which won't cause you troubles. One
of my favorites is #, because it uses a lot of ink (so it's easy for
the eye to pick out in the line) and because I hardly ever need it in
my patterns. Another good choice is one of the paired ones. Because
parentheses, square brackets, and curly braces are generally paired
inside patterns, the can be good choices for the outer delimiters as
well. (Perl's parser keeps count of the nested delimiters.)

That's why your second example above fails: The parser sees the
internal | character as the end of the pattern, even though the
parentheses aren't balanced there. Human-brain parsers tend to get
this parsing wrong. :-)

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to