Hi,

when trying to process continuation lines in a file, I ran
into a weird phenomenon that I can't make any sense of:

$s contains a line read from a file, that ends with a backslash
(+ the newline character), so

$s='abc \
';

$s =~ /^(.*)$/; print $1; # prints "abc \" as expected


If the line ends with a backslash, I don't want to include it
in the grouping, thus I use:

$s =~ /^(.*[^\\])(\\)?$/; print "1: '$1', 2: '$2'";


I would expect $1 to hold "abc " and $2=="\\", but instead,
the first grouping  holds everything including the backslash
and the following newline, while $2 is left undefined.

The perlre manpage says:
> .   Match any character (except newline)
> $   Match the end of the line (or before newline at the end)

but in my case the "." obviously matched the newline at the end.

When I do a chomp($s) first, everything behaves as expected,
while a "/m" at the end of the regular expression doesn't
make any difference.

Does anybody have an explanation what is going on here?

Regards,
                     Peter Daum


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to