sourcing one perl file from another

K

kc

Hi Perl gurus,

I've a question, and I was wondering if anyone could

I've a perl program, and I'm trying to make it tidier.

I have a huge file of a array of variables, for initialization,
something like this:

$key1[64]="0xc120718a1ccce7f8";
$key2[64]="0xeadf28cb82020921";
$key1[128]="0xaf503224b6cff0639cf0dc310a4b1277";
$key2[128]="0x3e1fcbd4e91ca24bb276914de3764cdf";

etc etc

Currently, they're all in the huge perl script file as the perl code
that uses it. I was hoping to separate this out to another file.

Is there any way for my mail perl file to read this file? I was
thinking of using a .pm file, but I was wondering if there was any
easier way?



Thanks,
Kelvin
 
M

Mumia W.

[...]
Is there any way for my [main] perl file to read this file? I was
thinking of using a .pm file, but I was wondering if there was any
easier way?

Read "perldoc -f do"

Example:
do "mydata.pl";
 
T

Ted Zlatanov

[...]
Is there any way for my [main] perl file to read this file? I was
thinking of using a .pm file, but I was wondering if there was any
easier way?

MW> Read "perldoc -f do"

MW> Example:
MW> do "mydata.pl";

....and make sure mydata.pl is treated as executable code, not as a
configuration. It's important for security to realize that do() is a
poor replacement for a decent configuration system.

Ted
 
T

Ted Zlatanov

k> I have a huge file of a array of variables, for initialization,
k> something like this:

k> $key1[64]="0xc120718a1ccce7f8";
k> $key2[64]="0xeadf28cb82020921";
k> $key1[128]="0xaf503224b6cff0639cf0dc310a4b1277";
k> $key2[128]="0x3e1fcbd4e91ca24bb276914de3764cdf";

k> etc etc

k> Currently, they're all in the huge perl script file as the perl code
k> that uses it. I was hoping to separate this out to another file.

k> Is there any way for my mail perl file to read this file? I was
k> thinking of using a .pm file, but I was wondering if there was any
k> easier way?

Use one of the following CPAN modules:

YAML (with the YAML data format)
AppConfig
XML::Simple (with the XML data format)

....or consider a file storage solution, depending on your exact needs.
Seems like you're doing binary data, so your needs may be very specific
and you may already have an input file from which you're extracting the
configuration data.

You don't have to use pure Perl for configurations, and in fact it makes
your program more complicated and less maintainable as you've
discovered. Crutches like do() will not help you in the long term.

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,052
Members
48,769
Latest member
Clifft

Latest Threads

Top