Just BTW (and it seems to make no difference in my experiments, your Line 7 lacks the closing double-quote found in OP's datum...

No. Everything inside unquoted [] inside qr// is a character class. Repeating characters inside [] is allowed, but has no effect. Double-quotes have no special meaning there, they are just like almost any other character. In fact, they are the first character only because I sorted all of the characters found in your $pattern line by their ASCII code:

>perl -E '$x=q[Category("notestrecord")];@a=split "",$x;say join "" => + sort grep { !$seen{$_}++ } @a' "()Cacdegnorsty >

You could move the double quotes to any other position between [] without any effect. See Bracketed Character Classes.

have not satisfied myself that I understand the implications of the discussion of 'normaliz(ation) in http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators.

Should not be very relevant here. The most important part (perhaps the only one?) is that RE modifiers are merged into the RE using embedded pattern-match modifiers ((?:pattern), (?adluimsx-imsx:pattern), or (?^aluimsx:pattern) notation):

>perl -e 'print "$_\n" for (qr/ab.c/,qr/ab.c/i,qr/ab.c/s,qr/ab.c/si)' (?^:ab.c) (?^i:ab.c) (?^s:ab.c) (?^si:ab.c) >

Enabling newer perl features may add the unicode flag:

>perl -E 'say for (qr/ab.c/,qr/ab.c/i,qr/ab.c/s,qr/ab.c/si)' (?^u:ab.c) (?^ui:ab.c) (?^us:ab.c) (?^usi:ab.c) >

See Extended Patterns.

Normalizing does not clean up redundant characters in character classes, nor does it sort characters in character classes - at least not in my perl 5.18.1. Enabling features does not change that. Using qr"" instead of qr// also has no effect:

>perl -e 'print "$_\n" for (qr/[abc]/,qr/[aabbcc]/,qr/[abcabc]/,qr/[cc +cbba]/)' (?^:[abc]) (?^:[aabbcc]) (?^:[abcabc]) (?^:[cccbba]) >perl -E 'say for (qr/[abc]/,qr/[aabbcc]/,qr/[abcabc]/,qr/[cccbba]/)' (?^u:[abc]) (?^u:[aabbcc]) (?^u:[abcabc]) (?^u:[cccbba]) >perl -e 'print "$_\n" for (qr"[abc]",qr"[aabbcc]",qr"[abcabc]",qr"[cc +cbba]")' (?^:[abc]) (?^:[aabbcc]) (?^:[abcabc]) (?^:[cccbba]) >

(Note that ALL of the test patterns match a single character a, b, or c).

There is a difference between $pattern="pattern"; $foo=~/$pattern/, $pattern=qr/pattern/; $foo=~/$pattern/, and $pattern=qr/pattern/; $foo=~$pattern: The first example is simple string interpolation, $pattern is just a simple scalar that will be compiled every time it is used in a regexp. The second and third example creates a Regexp object with a (possibly) compiled regular expression, using it in a regexp avoids recompiling it.

So, qr is not just a quoting operator for regular expressions (despite its name), but a constructor for Regexp (object) references. Those objects stringify to an equivalent (but not necessarily equal) regexp string. Perl may choose to compile the pattern inside the Regexp (object) reference. The exact wording in perlop is "This operator quotes (and possibly compiles) its STRING as a regular expression." in 5.20.1, "A string which is (possibly) interpolated and then compiled as a regular expression." in 5.005.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^4: Problem with input strings that have "[]" brackets by afoken
in thread Problem with input strings that have "[]" brackets by Laszlo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.