bihuboliya has asked for the wisdom of the Perl Monks concerning the following question:
I used the module in 1.pl as below:#!/usr/bin/perl package my_module; require Exporter; our @ISA = qw/Exporter/; our @EXPORT = qw/@my_var change_var/; our @my_var = (1..10); sub change_var{ @my_var = (20..30); } 1;
The other script 2.pl is as below:use my_module; print "@my_var\n"; # prints 1..10 change_var(); print "@my_var\n"; # prints 20..30 system("perl 2.pl"); # calling another script exit;
The changes made to the variable @my_var in 1.pl is not reflected in 2.pl. I want to make the variable @my_var global. Please let me know where I am wrong. Please suggest if I should take any other approach.use my_module; print "@my_var\n"; # prints 1..10 but expecting it to be 20..30
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sharing a variable across multiple files
by Eily (Monsignor) on Aug 07, 2013 at 09:30 UTC | |
by bihuboliya (Acolyte) on Aug 07, 2013 at 10:56 UTC | |
by bihuboliya (Acolyte) on Aug 07, 2013 at 12:28 UTC | |
|
Re: Sharing a variable across multiple files
by kcott (Archbishop) on Aug 07, 2013 at 10:00 UTC | |
by bihuboliya (Acolyte) on Aug 07, 2013 at 11:01 UTC | |
|
Re: Sharing a variable across multiple files
by Loops (Curate) on Aug 07, 2013 at 10:51 UTC |