in reply to left side of pattern matching
The second pass (equivalent to double-quoted literals) splits the string up into chunks of constant string mixed with variable access, \U etc; for example, "ab$c\Ud" gets converted into 'ab' . $c . uc('d'). For a normal double-quoted literal string, it would at this point also process all backslashy stuff, e.g. \n, \x{100}; however, for a regexp literal, this part is skipped.
Finally for regexps only, in the third stage the assembled string is passed to the regexp engine to be compiled. Here, the two characters \ and n are converted into a regexp op to match a newline, etc.
Note the difference this can make depending on whether it's a regex literal or a string literal:
Similarly,$foo =~ /\b/; # matches a word boundary $foo =~ "\b"; # matches a backspace
$s = '\n'; # note that's 2 chars, not a newline "\n" =~ /$s/; # matches
Dave.
|
|---|