On Feb 18, 2005, at 10:39 AM, Mark Wheeler wrote:

Hi,

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?

It's generally not a wise choice. Better to use something like Data::Dumper to write the data to a file, then load it back in the way the Data::Dumper manpage describes. Or YAML (as Rich pointed out), or Storable, etc.


If you don't like that approach, consider at *least* wrapping it in a subroutine:


---------------------------------------------------------- Script file ----------------------------------------------------------

#!/usr/local/bin/perl -w
use strict;
require variables.conf

print "Content-type: text/html\n\n";
foreach (&list) {
print;
}

exit;

---------------------------------------------------------
variables.conf
---------------------------------------------------------

my @list;

$list[0] = '1';
$list[1] = '2';
$list[2] = '3';
$list[3] = '4';
$list[4] = '5';

sub list { @list }

1;
---------------------------------------------------------



Reply via email to