On Apr 24, 10:58*am, Frank Seitz <devnull4...@web.de> wrote:
> Klaus wrote:
> > On Apr 24, 10:32 am, Frank Seitz <devnull4...@web.de> wrote:
> >> Klaus wrote:
>
> >>> It seems to me that Perl is confused about using '{' and '}' inside a
> >>> match of the form m{...}
> >> Perl is not confused. It's a syntax error, because { and } have a special
> >> meaning in regexes. See perldoc perlre (Section "Quantifiers").
>
> > Please note that I have escaped '\{' and '\}' inside m{\A\{0,0\}\z}...
>
> Here, the \-escape eliminates the meaning as delimiter.
> The { } become metacharacters.
>
> > ...and why does the message disappear if I use /\A\{0,0\}\z/. ?
>
> Here, the \-escape eliminates the meaning as metacharacter.
> The { } become normal characters.
Ok I see but this is rather confusing:
* in a // delimited regex the literal '/' has to be escaped
* in a {} delimited regex the literal '{' has *not* to be escaped
am I getting it right?
But then when I look at perlop
When searching for single-character delimiters, escaped delimiters
and "\\" are skipped. For example, while
searching for terminating "/", combinations of "\\" and "\/" are
skipped. If the delimiters are bracketing, nested
pairs are also skipped. For example, while searching for closing
"]" paired with the opening "[", combinations of
"\\", "\]", and "\[" are all skipped, and nested "[" and "]" are
skipped as well. However, when backslashes are
used as the delimiters (like "qq\\" and "tr\\\"), nothing is
skipped. During the search for the end, backslashes
that escape delimiters are removed (exactly speaking, they are not
copied to the safe location).
it gets more confusing. If I understand correctly the difference is
only there if the { } are paired.
In m{ aaa{bbb } the { is not escaped and it is understood as the
beginning of a quantifier.
In fact I get:
Search pattern not terminated at ./test.pl line 6.
So to have a literal '{' I should escape it if not paired and not
escape it if not paired.
Did I get it wrong? (I sincerly hope so
Matteo