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

Re: [MacPerl] Callbacks not reliable?



Keary Suska wrote:

> >I had always thought in m// or s/// that if the pattern doesn't match that
>>the callback variables (i.e. $1, $2, $3 ...) would be undefined. I am
>>finding that this isn't the case at least with a substitution.

Chris Nandor replied:

>It seems fine to me.

Chris:

I understood Keary differently than you did.

Consider the following script:

#!perl
$test1 = "This is a test";
$test2 = "Also a test";

$test1 =~ s/(a test)/reality/;

print "First substitution: $1\n";

$test2 =~ s/(a monkey)/a cow/;

print "Second substitution: $1\n";

__END__

The output you get is:

First substitution: a test
Second substitution: a test

The output I think Keary expected was:

First substitution: a test
Second substitution:

I have also found this annoying, but have never (unlike Keary) 
noticed Perl to behave otherwise.

HTH

-David-
David Steffen, Ph.D.
President, Biomedical Computing, Inc. <http://www.biomedcomp.com/>
Phone: (713) 610-9770 FAX: (713) 610-9769 E-mail: steffen@biomedcomp.com

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org