Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global variable

Status
Not open for further replies.

scribouille

Programmer
May 10, 2001
6
FR
Hello,
Including the package strict in all my files in ".pl" and ".pm", I declare global variables in my main perl programm.
But I can't see these variables in the other files in ".pl" or ".pm" whereas I declare these global variable like this :
use vars qw ($var1 $var2 $var3);
I don't understand why. The package vars would have to enable me to use these global variables in files which are inculded in my main perl program.
Thank's for your help
 
are there any error messages?

the following works perfect on my system:
[tt]
---------main.pl---------

#!/usr/bin/perl -w
use strict;
use vars qw($var1 $var2 $var3);
$var1 = 'hello';
$var2 = ', ';
$var3 = 'world';

require "test.pl";


----------test.pl---------

#!/usr/bin/perl -w
use strict;
print $var1, $var2, $var3, "!!!!!\n";
1;

----------output----------

>perl main.pl
hello, world!!!!!
[/tt]
? "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top