http://qs1969.pair.com?node_id=240486

LameNerd has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,
I have this package:
package MYPACKAGE; use Exporter; use vars qw / $VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS /; $VERSION = 1.0; @ISA = qw/ Exporter /; @EXPORT = (); @EXPORT_OK = qw / sub1 /; %EXPORT_TAGS = ( DEFAULT => [ qw / sub1 / ] ); use strict; my $var1 = "DEFUALT I WANT TO CHANGE"; sub sub1 { print "var1 = $var1\n"; } 1;
Now I use this packe in this script like so:
#!/usr/bin/perl -w use strict; use lib ('.'); use MYPACKAGE qw / sub1 /; use vars qw / $var1 /; $var1="PRINT THIS"; sub1();
The output is:
var1 = DEFUALT I WANT TO CHANGE
I was hoping that the output would be
var1 = PRINT THIS
How come the value of $var1 didn't change when I did $var1="PRINT THIS";
in my script?