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

> What do you call "passed variable"?

sub tst (&$) { $_[1]++; # passed variable $_[0]->(); # passed block } tst { print $c} $c;

Cheers Rolf

Replies are listed 'Best First'.
Re^7: localizing lexical without messing with tie ?
by ikegami (Patriarch) on Sep 10, 2010 at 01:50 UTC

    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).

      > 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().