develooper Front page | perl.perl5.porters | Postings from March 2006

Re: A user pragma example

Thread Previous | Thread Next
From:
David Nicol
Date:
March 31, 2006 14:32
Subject:
Re: A user pragma example
Message ID:
934f64a20603311432t74d69061y2a30c151945c0553@mail.gmail.com
so something like this would work?

package namedscope;
=pod

Scalars can be tied to this package and they will be in a
virtual scope named at compile time using the namedscope pragma.

Example:

     tie our $n, 'namedscope';

     {
         use namedscope 'foo';
         $n = "in foo scope";
     }
     {
         use namedscope 'bar';
         $n = "in bar scope";
     }

     {
         use namedscope 'foo';
         print "$n\n";
         use namedscope 'bar';
         print "$n\n";
     };

=cut

sub import{
   $^H{namedscope} = shift;
};
sub TIESCALAR{
   return bless {};
};
sub STORE{
   $_[0]->{$^H{namedscope}} = $_[1]
};
sub FETCH{
   $_[0]->{$^H{namedscope}}
};

1;
__END__



--
David L Nicol
"the opportunity of making good with a hard undertaking - one that had
been held impossible of realization - would be a strong asset to the
firm's reputation" -- William Russell, 1860
http://cronos.advenge.com/pc/americana/PonyExpress/p15.html

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About