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

package 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;
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:11

In reply to Re^2: Exporting subs from package required in an eval by Anonymous Monk
in thread Exporting subs from package required in an eval by cfreak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.