
japhy
Enthusiast
Sep 16, 2000, 8:46 AM
Post #2 of 3
(311 views)
|
The 'strict' pragma only effects the current scope you are in. use()ing and require()ing files executes the file in an UNRELATED scope, so while your main program may have strict on, the files you require don't need to have it on, nor will they be under the effects of strict. However, your main program still has to behave like strict wants it to. Now, my() variables only exist in the scope in which they are defined. That means that my()ing a variable in your main program, and trying to use it in a require()d file (or vice-versa) will not work. So they'll have to be global variables. You can either preface them with a package name (main:: or the name of the package you define the variables in), or declare them with use vars. <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> # define.pl package CONFIG; $host = 'perlguru.com'; $user = 'japhy'; $password = 'not on your life'; # main.pl use strict; require 'define.pl'; print "Hello, $CONFIG::user.\n"; </pre><HR></BLOCKQUOTE> Here's the other method: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> # define.pl $host = 'perlguru.com'; $user = 'japhy'; $password = 'not on your life'; # main.pl use strict; use vars qw( $host $user $password ); require 'define.pl'; print "Hello, $user.\n"; </pre><HR></BLOCKQUOTE> ------------------ Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher
|