Question : Exporting variables from module on windows

The code I've posted will work on linux.  But when I try to run it on Windows, I get the following error:

Global symbol "%hash" requires explicit package name at H:\test.pl line 6.
Execution of H:\test.pl aborted due to compilation errors.

I've declared %hash in test.pm with "our".  I have %hash in the @EXPORT array.  Why would I get this error when the exact same code works on linux?

 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
# MODULE
package test

use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);

use Exporter;
$VERSION = 1.00;
@ISA = qw(Exporter);

@EXPORT = qw(%hash);  # Symbols to autoexport
@EXPORT_OK = qw(); # Symbols to export by request
%EXPORT_TAGS = (); # Define names for sets of symbols

our %hash;
$hash{tag} = value;

1; # This is required.  Do not delete this line!

# SCRIPT
#!perl

use strict;
use test;

print "$_\n" for keys %hash;

Answer : Exporting variables from module on windows

I have found the problem... took me awhile...
It just happened that there's already a module called test.pm under C:/Perl/lib/test.pm and that module takes precedence over your module.
Here are the choices:
   * use 'use lib' for force Perl to use your test.pm (use lib qw(/your/dir);)
   * or better, use another name for module, such as MyTest.pm (example below)

BTW, you should only export when needed.
Otherwise using something like %MyTest::hash is probably a better (more explicit) way to go.

Good luck!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
C:\home\jerome>type ee1.pl
#!perl

use strict;
use MyTest;

print "$_\n" for keys %hash;





C:\home\jerome>type MyTest.pm
package MyTest;

use strict;
use base qw(Exporter);

our @EXPORT = qw(%hash);

our %hash = ( tag => "value" );

1; # This is required.  Do not delete this line!




C:\home\jerome>perl ee1.pl
tag
Random Solutions  
 
programming4us programming4us