On 8/5/06, Peter Daum <[EMAIL PROTECTED]> wrote:

$s='abc \
';

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

Let's see what that pattern matches by annotating it:

 m{
   ^       # start of string
   (       # memory 1
     .*    # any ol' junk, including backslashes
     [^\\] # any non-backslash, including newlines
   )
   (\\)?   # optional backslash (memory 2)
   $       # end of string (or final newline at eos)
 }x

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 "." obviously matched the newline at the end.

No, the "." matched the backslash; the "[^\\]" matched the newline.

Does that get you back on the right track? Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
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