------------------------------------------ test.cgi ------------------------------------------
#!/usr/bin/perl -w
use strict;
our @list; require 'variables.conf';
foreach (@list) { print; }
exit;
------------------------------------------- variables.conf -------------------------------------------
$list[0] = '0'; $list[1] = '1'; $list[2] = '2'; $list[3] = '3'; $list[4] = '4';
1;
-------------------------------------------------------------------
What am I missing here? Thanks for your help.
Mark
On Feb 18, 2005, at 8:54 AM, Neil Bowers wrote:
Just a quick question. Is it possible to have a bunch of variables in a separate file and then require that file in the script file? Let me give you and example.
[...]
require variables.conf
[...]
variables.conf
[...]
my @list;
[...]
When I try the above script, I get an error - "Global variable @list needs to be defined". What am I doing wrong, or is this even possible?
The scope of my @list is the file where it's declared. From 'perldoc -f my':
A "my" declares the listed variables to be local (lexically) to
the enclosing block, file, or "eval". If more than one value
is listed, the list must be placed in parentheses.
You'll need to declare the variable in the script ('our', not 'my'), before you require variables.conf
Neil