in reply to Re^2: Sharing a variable across multiple files
in thread Sharing a variable across multiple files
I used the do function in the first script to execute the second script in the same context (shared memory without creating another process by using system(..)). Though, I had to pass some arguments to the second script. do "2.pl $arg1" does not work.
Finally I came to know that if we want to pass argument to the second script, we can exploit the idea that @ARGV will be visible to the second script. I achieved the goal as below:
Now, in 2.pl I can get these arguments using shift.use my_module; print "@my_var\n"; # prints 1..10 change_var(); print "@my_var\n"; # prints 20..30 { # using local to supress @ARGV local @ARGV = ($arg1, $arg2...); # $arg1, $arg2... are the argumen +ts to be passed do "2.pl"; } exit;
Regards,
--Anupam
|
|---|