CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
require, use and global variable



May 9, 2001, 11:57 PM

Post #1 of 3 (2983 views)
require, use and global variable Can't Post

I have a strnge thing with my Perl program :
a global variable (using strict), an instance of a class,
is not visible in certains files in ".pl". Why, please ?
About requires and uses : I have to specify the total path (even with use) in my main whereas, in the biblio. files in ".pl" or in the packqge in ".pm", I have to specify the relative path (thanks to use). i don't understand why...
Thank's for your help


May 10, 2001, 2:38 PM

Post #2 of 3 (2972 views)
Re: require, use and global variable [In reply to] Can't Post

About variables:

The short answer is that my and local variables do not travel well. In order to use or require them into another file you must declare them with

use vars qw ($var1 @var2);

For the longer answer look to this blast from the past.

About use/require directories.

It could be that your main is trying to use or require a file that is not in a known directory and you would have to give the whole name.

To see what directores are in the path you can type "perl -V" at the command prompt in a UNIX or DOS shell. The -V is for verbose and will tell you all kinds of stuff about your version of perl, but the last thing it tells you is the contents of the @INC which is the list of directories to look in when you use or require.

If you have a directory with all your modules and it is not in your current directory or one in the @INC you can add it to the @INC with...

use lib '/path/to/lib/dir';

Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?


May 16, 2001, 3:04 AM

Post #3 of 3 (2954 views)
Re: require, use and global variable [In reply to] Can't Post

Thanks but... I have already done it
For the 1rst one : I declare my variable with use vars qw ($my_var). But, another thing, this variable id in fact an instance of a class and could not be seen in ".pl" files, containing functions...

For the 2nd. one : i add the good path of my ".pl" and ".pm" files with lib, which can be viewed with the "-V" option in @INC... But I still have to specify the entirely path or the partial path following ".pm" or ".pl" files...


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives