in reply to Re: problem referencing global variable in self-written module
in thread problem referencing global variable in self-written module

Okay, I updated both script and module as you suggested:

testuse.pl
#!perl; use warnings; use strict; use Fleece qw( $fleece ); my $BNAME = 'Mary'; print "$BNAME had a little lamb, little lamb, little lamb,\n"; print "$BNAME had a little lamb,\n"; print "It's fleece was $fleece.\n";

Fleece.pm
package Fleece; use warnings; use Exporter; our @EXPORT_OK = qw( $fleece ); our $fleece = "white as snow.\n"; 1;
I got this error when I tried to execute the script:
Global symbol "$fleece" requires explicit package name at testuse.pl l +ine 11. Execution of testuse.pl aborted due to compilation errors.

Replies are listed 'Best First'.
Re^3: problem referencing global variable in self-written module
by ikegami (Patriarch) on Jun 08, 2006 at 21:21 UTC
    our @ISA = 'Exporter'; is missing in the module. I forgot about that in my initial post.
    package Fleece; use strict; use warnings; use Exporter; our @ISA = 'Exporter'; our @EXPORT_OK = qw( $fleece ); our $fleece = "white as snow.\n"; 1;

    Tested.

      I must be doing something else wrong. I downloaded your code, over-writing the text in my "Fleece.pm" module. The same error greeted me when I tried to run "testuse.pl". Here are more details, though I am unsure if any of them matter. The "testuse.pl" script is in my "C:\Documents and Settings\yburge" folder. When I open a command prompt, that's where I am by default. The "Fleece.pm" module is in the "C:\Perl\site\lib" folder.

      BTW, I noticed in down-loading your code, the "expected" file extension was ".pl". Would that make any difference?

        Print $INC{'Fleece.pm'} to make sure you are using the Fleece.pm you think you are using.

        Perl Monks assumes everything in code tags is Perl code, and it can't tell the diff between code which should be a in .pm and other code. For use Fleece to work, you'll need to name the file Fleece.pm.