in reply to localizing lexical without messing with tie ?

You don't need local for lexicals.

Just shadow the name in the inner scope. So simple:

#! perl -slw use strict; { package NewStdScalar; require Tie::Scalar; our @ISA = qw(Tie::StdScalar); sub FETCH { return ${+shift}++ } } package main; tie my $scalar, 'NewStdScalar'; $scalar=0; print $scalar; # 0 { my $scalar = "---"; # --- print $scalar; } print $scalar; # 1 __END__ C:\test>junk34 0 --- 1

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

Replies are listed 'Best First'.
Re^2: localizing lexical without messing with tie ?
by ikegami (Patriarch) on Sep 08, 2010 at 03:18 UTC
    That's not equivalent since the inner variable isn't tied.

      #! perl -slw use strict; { package NewStdScalar; require Tie::Scalar; our @ISA = qw(Tie::StdScalar); sub FETCH { return ${+shift}++ } } package main; tie my $scalar, 'NewStdScalar'; $scalar=0; print $scalar; # 0 { tie my $scalar, 'NewStdScalar'; $scalar = "---"; # --- print $scalar; } print $scalar; # 1 __END__ C:\test>junk34 0 --- 1

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re^2: localizing lexical without messing with tie ?
by LanX (Saint) on Sep 08, 2010 at 16:34 UTC
    Trivially "shadowing" is not the point and not possible in my use case.

    I really need to localize a passed variable which is used in a passed codeblock, but your example introduces a completely new var.

    Cheers Rolf