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

> 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

  • Comment on Re^8: localizing lexical without messing with tie ?

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

    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

        no named parameters

        I have no idea what you mean since the entire purpose of tst in the code you posted is to provide named parameters (using a bad syntax). Could I buy a verb please?

        UPDATE: oversaw the readmore-part,

        It's not behind a readmore.

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

        tie is the Pure Perl interface to Magic. It's implemented using Magic, so anything tie can do, so can Magic.

        You're looking for any magic that has a side-effect that isn't undone by the end of the following:

        my $saved = $magical; ... $magical = ...; ... $magical = $saved;