I'm trying to create a global variable in my main script, then when I 
load a Perl module, in it, I want to create an alias to that global in 
the loaded Perl module. But, when I call a function in that module, the 
variable is empty (though I know that the global in my script isn't 
empty). I wanted to use Data::Alias, as suggested in the book "Perl Best 
Practices", but I'm working in the Windows world and it doesn't seem to 
be available via ppm for ActiveState perl. So, I'm using a library named 
simply "Alias", which comes with ActivePerl. Anyway, here's the code:

# 
---------------------------------------------------------------------------

# SamplePerlScript.pl

package main;

use strict;
use warnings;

our $StudentID;

use SamplePerlModule;

MAIN: {
$StudentID = 801;
test();
} # MAIN()

# 
---------------------------------------------------------------------------

# SamplePerlModule.pm

package SamplePerlModule;

use strict;
use warnings;

use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(test);

use Lexical::Alias;
$Lexical::Alias::SWAP = 1;

alias my $StudentID => $main::StudentID;

sub test {

my $id = $StudentID || 'none';
print("in test(): StudentID = $id\n");
} # test()

1;
# 
---------------------------------------------------------------------------

OUTPUT:

in test(): StudentID = none


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to