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?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.