in reply to Re: Code in regexp
in thread Code in regexp

Is the local() needed abigail? I was playing with this yesterday and didnt seem to need it.

--- demerphq
my friends call me, usually because I'm late....

Replies are listed 'Best First'.
Re: Code in regexp
by Abigail-II (Bishop) on Nov 29, 2002 at 09:50 UTC
    No, it's not needed. Just like use strict and my aren't "needed". But if your code happens to have a $main::x, you'll be thankful you used local.

    Abigail

      Er, sarcasm aside, the reason I asked was because the documentation suggested to me that they were automatically localized.

      --- demerphq
      my friends call me, usually because I'm late....

        $x = $y = "apple"; "orange" =~ /(.*)(?{$x = $^N; local $y = $^N})/; print "$x\n$y\n"; __END__ orange apple

        If all variables would be automatically localized, it would be hard to pass any information from the regex back to the program.

        I can't find something in the documentation that suggests variables are automatically localized.

        Abigail