On 7 June 2010 14:42, Yossi Itzkovich <[email protected]> wrote:
>
> 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 ?
>
Sort of.
There are two passes, but there are two '$' characters, which are distinct.
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.
To compile the regex Perl first interpolates variables (presumably
containing subpatterns), so:
my $input = ".*"; # or better written as qr/.*/;
/$input/;
is the same as:
/.*/;
However, in your program contains the *string* '$input', which will not be
further interpolated (unless you manually call string eval).
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.
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).
In order to match a literal $ you need to escape it in the pattern,
regardless of whether or not you use interpolation.
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl