View Full Version : Accessing declared variables from requried file
chrisbragg
01-06-2004, 03:56 PM
Hello
I think this should be an easy question. Lets say I have the script below:
my($variable);
require('somefile.pl');
How can I gain access to the scalar "$variable" inside the "somefile.pl" without not using "my". I know it works if I don't use "my", but then I cannot "use strict". I'm sure there is an easy way to do this sort of thing.
Thank you-
Jeff Mott
01-06-2004, 05:34 PM
You can declare $variable with our instead of my.
dswimboy
01-06-2004, 05:36 PM
i think you can access it using $main::variable
YUPAPA
01-06-2004, 06:37 PM
Originally posted by dswimboy
i think you can access it using $main::variable
that only works for module I fink~ :p
chrisbragg
01-07-2004, 06:16 AM
Thank you!
For all I've read abou PERL, I had never come across the "our" declaration.
Now, all my scripts can be strict.
Thank's again.
dswimboy
01-07-2004, 04:25 PM
Originally posted by YUPAPA
that only works for module I fink~ :p
well, since he is using 'require' he is using the other script as a library. and i think libraries can access the main method in that fashion. i will test it when i get home and let you know :)
dswimboy
01-08-2004, 01:31 AM
YUPAPA you were correct. i couldn't get it to work. the our declaration is wonderful, i've never come accross it either. way to go!
YUPAPA
01-08-2004, 06:45 AM
no problem~ :p
Everyone is trying to help here, I understand no one wants to give out inaccurate info~ :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.