perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Philip Mak <p...@aaanime.net>
Subject Human readable flatfiles
Date Thu, 01 Jun 2000 13:39:42 GMT
Hello,

I would like to ask a question about maintaining human readable flatfiles
in general.

I have a perl (non-modperl) program that needs some input data. Currently,
it reads in the data by "require"ing another perl script that has
statements to set the variables (as global variables). I did it this way
so that I can easily edit the include file if I want to change values,
and I can even put code in the include file to calculate values.

But, I am finding that this does not work in modperl under "use strict".
Apparently, code in a file called by require is not in the same variable
scope. (If "use strict" is off, it works sometimes but other times the
variables come out with the values from the previous invocation.)

Here is an example of what I currently have:

$series = $ENV{'QUERY_STRING'};
require "series_$series.i";
(do something with the variables $series_name, $series_prefix)

and inside series_ranma.i, I have:

$series_name = 'Ranma 1/2';
$series_prefix = 'Ranma';
@series_data = (
<insert list here>
);

but this does not work, since in modperl the required file has a different
variable scope.

Two ideas I am thinking of are:

(1) make series_$series.i into a text file instead, like this:

Ranma 1/2
Ranma
<insert list here>

and read it in with fopen(SERIES, "series_$series.i") and <SERIES>. But
then I wouldn't be able to put perl code inside it and it is less clear.

(2) make series_$series.i into a subroutine that returns its values. I can
require it, and then call the subroutine and get the return values, but
this seems kind of kludgy to me.

Does anyone have a better suggestion for maintaining human readable
flatfiles containing data to be read? Is there a good CPAN module for it
perhaps?

Thanks,

-Philip Mak (pmak@aaanime.net)

P.S. When replying to this message, please make sure my e-mail address is
in the to field. I'm not sure if I'm subscribed to this mailing list or
not. It seems to keep kicking me off or something, because I haven't been
receiving any mail from it.


Mime
View raw message