<div dir="ltr"><div><br></div>On 7 June 2010 14:42, Yossi Itzkovich <span dir="ltr"><<a href="mailto:Yossi.Itzkovich@ecitele.com">Yossi.Itzkovich@ecitele.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<div lang="EN-US" link="blue" vlink="purple"><div><div><div><div><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125); ">Does it means there are two passes on the reg ex: one that interpolates the dollar as a scalar, and the second that treats it as a regex metacharacter ?</span></p>
</div></div></div></div></div></blockquote><div>Sort of.</div><div><br></div><div>There are two passes, but there are two '$' characters, which are distinct.</div><div><br></div><div>The first is the $ that appears in the program that signifies a variable, and the second is the $ that was read from input was inside the variable.</div>
<div><br></div><div>To compile the regex Perl first interpolates variables (presumably containing subpatterns), so:</div><div><br></div><div> my $input = ".*"; # or better written as qr/.*/;</div><div> /$input/;</div>
<div><br></div><div>is the same as:</div><div><br></div><div> /.*/; </div><div><br></div><div>However, in your program contains the *string* '$input', which will not be further interpolated (unless you manually call string eval).</div>
<div><br></div><div>Once the regex is constructed as a string, it's parsed with the regex syntax. At this point the '$' is a zero width assertion, and the string "input" found after it is a string literal.</div>
<div><br></div><div>This doesn't really make sense for line by line matching, but the pattern '$input' could be useful using the /m modifier (matching a line starting with "input" that isn't the first line in the string).</div>
<div><br></div><div>In order to match a literal $ you need to escape it in the pattern, regardless of whether or not you use interpolation.</div></div>