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

RE: [MacPerl] Callbacks not reliable?



Actually, it would be in a local() scope, which is what Chris Nandor said...

-K


----------
> From: Keary Suska <aksuska@insideflyer.com>
> Date: Thu, 14 Sep 2000 17:50:05 -0600
> To: MacPerl <macperl@macperl.org>
> Subject: Re: [MacPerl] Callbacks not reliable?
> 
> The problem/quirk I am noticing can be shown with the following change to
> Chris's code below:
> 
> #!perl -wl
> $_ = 1;
> foo(1);  # 1
> foo(2);  # undef
> /(1)/; print $1;  # 1
> /(2)/; print $1;  # 1
> foo(2);
> 
> sub foo {
> /($_[0])/;
> print $1;
> }
> 
> I would think that the $1 in Main is in a different scope than the $1 in foo.
> But this does not necessarily seem the case...
> 
> -K
> 
> "Do not meddle in the affairs of dragons, because you are crunchy and taste
> good with ketchup."
> 
> 
>> From: Chris Nandor <pudge@pobox.com>
>> Date: Thu, 14 Sep 2000 19:07:50 -0400
>> To: Ronald J Kimball <rjk@linguist.dartmouth.edu>
>> Cc: Keary Suska <aksuska@insideflyer.com>, MacPerl_List <macperl@macperl.org>
>> Subject: Re: [MacPerl] Callbacks not reliable?
>> 
>> At 18:35 -0400 2000.09.14, Ronald J Kimball wrote:
>>> On Thu, Sep 14, 2000 at 03:31:49PM -0600, 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.
>>> 
>>> That is incorrect.  $<digit> and the other regex special variables contain
>>> the values from the last *successful* pattern match in the current scope.
>>> An unsuccesful match does not reset these variables.
>> 
>> But these variables are automatically local()d to the enclosing block, I
>> think:
>> 
>> #!perl -wl
>> $_ = 1;
>> foo(1);  # 1
>> foo(2);  # undef
>> /(1)/; print $1;  # 1
>> /(2)/; print $1;  # 1
>> 
>> sub foo {
>> /($_[0])/;
>> print $1;
>> }
>> 
>> -- 
>> Chris Nandor                      pudge@pobox.com    http://pudge.net/
>> Open Source Development Network    pudge@osdn.com     http://osdn.com/


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