in reply to Re^6: localizing lexical without messing with tie ?
in thread localizing lexical without messing with tie ?

So "override a global lexical variable for a dynamic scope", where you have access to the global via an alias.

Could you use $_, $a and $b or arguments instead?

I don't see how PadWalker would help. If you found a solution using it, it might be possible to recreate the solution using B (a core module).

Replies are listed 'Best First'.
Re^8: localizing lexical without messing with tie ?
by LanX (Saint) on Sep 10, 2010 at 11:45 UTC
    > Could you use $_, $a and $b or arguments instead?

    no, it's intended to allow an unlimited number of vars, and as a side note $a and $b could be tied too.

    As I said, forbidding tied vars is a good and pragmatic solution to get around this edge case.

    Cheers Rolf

      it's intended to allow an unlimited number of vars

      Arguments do allow that. It seems that what you want is named arguments. Maybe you should use Sub::Parameters or something like that.

      You're striving for the awkward

      my $c; thing { ... ... $c ... ... } $c;
      but the following is clearer:
      thing { my $c : Parameter; ... ... $c ... ... };

      and as a side note $a and $b could be tied too.

      So? I've already shown you how to completely localise a package variable.

      The advantage of $a, $b and $_ is that you don't need to declare them.

      As I said, forbidding tied vars is a good and pragmatic solution to get around this edge case.

      There are a lot more magic variables than just tied ones, but you're not likely to find them on lexicals without putting it on them explicitly.

      You'll also clobber dualvars and vars' pos().

        no named parameters and your code was - AFAI understood- basically about an automatic undoing of localization.

        UPDATE: oversaw the readmore-part, I'm going to have a closer look at it, but as I said tied vars are really an edgecase, it's over-optimization to care about it now and to invest so much code.

        No need for that I can undo it explicitly.

        The code I posted using untie does exactly what I need for pack-vars.

        > There are a lot more magic variables than just tied ones, but you're not likely to find them on lexicals without putting it on them explicitly.

        Could you show me an example with pack-vars where magic (other than tie) results in problems after an explicit local?

        DB<1> sub tst { local $_[0]; $_[0]=10 } DB<2> $a=1 DB<3> tst $a DB<4> print $a 1

        Cheers Rolf