Next Tricks of the Wizards 64

Exporting a Magical Variable

        package Eval;
        sub import {
          my ($package, $name) = @_;
          $name = 'Eval' unless defined $name;
          my %magical_hash;
          tie %magical_hash => Eval;
          my $caller = caller;

          *{$caller . '::' . $name} = \%magical_hash;
        }
        sub TIEHASH {
          my $self = \'dummy';
          bless $self => 'Eval';
        }


Next Copyright © 2003 M. J. Dominus