in reply to Re: Exporting subs from package required in an eval
in thread Exporting subs from package required in an eval
Sorry for grave-digging, but this seems to be the closest thread that search manages to discover.
I'm trying to use a runtime-determined module (a game rules plugin for a game server). I want to import some functions and scalars into main namespace. Both eval "use $modulename"; and "eval require then manually import" as described above import the subs successfully, but fail to import scalars. I could, of course, manage with wrapping scalars into getter-setter functions but something seems funny here... Could anyone explain/help?
main.pl
use strict; use warnings; my $x='Exports'; eval "use $x"; asub(); #fails if I uncomment the next line - Global symbol "$ascalar" require +s explicit package name #print $ascalar, "\n";
Exports.pm
I'm using latest ActivePerl on Windows This is perl, v5.10.1 built for MSWin32-x86-multi-thread (with 2 registered patches, see perl -V for more detail) Copyright 1987-2009, Larry Wall Binary build 1007 291969 provided by ActiveState http://www.ActiveState.com Built Jan 26 2010 23:15:11package Exports; use strict; use warnings; use Exporter; use base 'Exporter'; our @EXPORT = qw( $ascalar asub); our $ascalar = 42; sub asub { print "sub called\n"; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Exporting subs from package required in an eval
by Corion (Patriarch) on May 06, 2010 at 14:10 UTC | |
by Anonymous Monk on May 06, 2010 at 15:04 UTC |