I'm confused about the left side of pattern matching operators as they pertain to escaped characters. For the following program:
use strict; use warnings; my $hello = "\n |\t\r"; if ($hello =~ m/^[ \|\t\r\n]+$/){ print "yep this matches"; } else { print "no this doesn't match"; } exit;
This performs about as I "wanted" i.e. that it matches the $hello string, but I'm still a little confused as to why. From my reading of the Perl docs I know there are two passes: a limited double quote parsing followed by a regular expression interpretation. I would expect that in the first pass, those characters would be converted to their "real" forms, like actual newlines and tabs, and the backslash simply removed from before the pipe. However, it seems this isn't happening. So, does that mean that the only form of interpretation in the first pass is to interpolate variables, or is there anything else? Thanks for your clarification.

In reply to left side of pattern matching by BeneSphinx

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.