[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] [Q] use of $1, $2...



At 14.00 -0400 1998.06.30, Nobumi Iyanaga wrote:
>I have a script like this:
>
>$_ = " abcde. egi";
>
>if (/^(.+\.)([^\.]*)/) {
>	$a = $1;
>	$a =~ s/ //;
>	$b = $2;
>}
>
>print "a = $a, b = $b\n";
>
>When I run this script, the result is:
>
>a = abcde., b =
>
>But if I comment out the line "$a =~ s/ //;", I get the expected result:
>
>a =  abcde., b =  egi
>
>Must I think that something is changed in $2 when I remove the space in $a??
>
>Thank you in advance for any explanation.

When you do a new regex ($a =~ s/ //;), $1 and $2 are reset.  Put the
assignment $b = $2 before the next regex.

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch