On Tuesday, July  1 at 10:40 AM, Bernie Cosell wrote:
> What I don't understand is why 
> the powers-that-be provide so much resistance to putting in a simple 
> 'static' declaration that would work the same way, only be defined-and-
> legal.  e.g.,:
>    sub x
>    {   static $vbl ;
>         [...]
> 
> Oh well, I guess re-opening that wound isn't much fun...

But, that example sounds kind of fun to me :

package mystatic;
{   my %vars;
    sub TIESCALAR { my $key = $_[1]; $vars{$key} = undef unless exists $vars{$key}; 
bless \$key,$_[0]; }
    sub FETCH { $vars{${$_[0]}} };
    sub STORE { $vars{${$_[0]}} = $_[1]; } 
}

package main;
sub static (\$) {
    my @caller = caller 1;
    tie ${$_[0]},'mystatic',"$caller[3]::$_[0]";
}

sub x { static $vbl; print ++$vbl; }
sub z { static $vbl; print ++$vbl; }

x; x; z; z;

output: 1212

Or 'static my $vbl' would satisfy strict refs.

-Brian

Reply via email to