This question is a follow on question to a previous one at http://www.perlmonks.org/?node_id=1057587, from a number of days back. I did post this follow-up query in that post, but I think the post is probably not being viewed any more.

So, the original question was to do with passing arguments from a script to a module; I can now get that bit working. However, the solution seems to introduce another problem, which I don't quite understand.

The test module, and test script, are shown below:

The module
package my_testmodule; $VERSION = '1.00'; use strict; use warnings; our $gMessage; undef our @list; use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(@list); sub import { my $class = shift; $gMessage = shift; print "Yep, I'm in here ...\n\n"; my_sub(); } # &my_sub; sub my_sub { print "$gMessage\n\n" if ($gMessage); push (@list,'oranges','lemons','apples'); } 1;
The script
#!/usr/bin/perl use strict; use warnings; use my_testmodule 'xyz'; print "$list[0]\n\n"; exit;

Previously, before trying to pass the module anything at all, and thus without the import sub, I would be able to read @list, defined in the module, in test.pl.

However, now, with the import sub, I'll get an error when running test.pl, "Global symbol "@list" requires explicit package name at test.pl line 8."

I don't see why this should be, seeing as it appears to be defined and exported properly in the module; in fact nothing to do with @list has changed.

I did also try referencing $list with the package name, but that doesn't work either.

Any help/suggestions would be much appreciated. Thanks!


In reply to Variable Scope by DanielSpaniel

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.