in reply to Re: Sharing a variable across multiple files
in thread Sharing a variable across multiple files

Hi Eily, thank you for your suggestion. I did run the second script as do "2.pl" and that solved the problem :)
  • Comment on Re^2: Sharing a variable across multiple files

Replies are listed 'Best First'.
Re^3: Sharing a variable across multiple files
by bihuboliya (Acolyte) on Aug 07, 2013 at 12:28 UTC
    Dear Monks, I gained some additional wisdom about the function 'do' which I would like to share.

    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:

    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;
    Now, in 2.pl I can get these arguments using shift.

    Regards,

    --Anupam