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

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