in reply to Variable scoping in packages

You can't export lecically scoped ("my") variables. You're exporting a package variable by the same name.

Replies are listed 'Best First'.
(tye)Re: Variable scoping in packages
by tye (Sage) on Oct 10, 2001 at 00:39 UTC

    Actually you can, you just can't use Exporter.pm to do it. (:

            - tye (ya know)
      You're not going to get away with just a teaser, you know.

        Define a package:
        package Pack; my $foo = 'pack'; sub import { my $pkg = caller(); no strict 'refs'; *{ $caller . '::foo' } = \$foo; } 1;
        Now write a program:
        #!/usr/bin/perl -w use strict; use Pack; print "$foo\n";
        After realizing that names have scope, variables do not (Dominus once said something similar), print out this page. Then eat it. :) ©