On Jul 11, Rory O'Connor said:

>I want to "use strict" in a script I'm writing.  I have a separate
>config file I am using (require "config.pl";) with a bunch of global
>variables.  But my script doesn't seem to want to recognize those
>variables unless they are actually declared in the body of the script
>itself.
>
>I tried using "my $variable = whatever;" in the config file but it
>didn't seem to work either.  Does this mean that if I use strict I can
>only use variables I declate in the script itself?

my() variables exist only where you declare them.  You can't share them
between files.  You need to declare global variables with either our() (if
you're using Perl 5.6) or use vars.

  #!/usr/bin/perl
  # perl 5.6+

  use strict;
  use warnings;

  require "somefile.pl";
  our ($vars, @defined, $in, %somefile);

or

  #!/usr/bin/perl -w
  # pre-perl 5.6

  use strict;

  require "somefile.pl";
  use vars qw( $vars @defined $in %somefile );

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to