sourcing one perl file from another

sourcing one perl file from another

am 22.10.2007 11:52:31 von 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

Re: sourcing one perl file from another

am 22.10.2007 12:08:58 von paduille.4061.mumia.w+nospam

On 10/22/2007 04:52 AM, kc wrote:
> [...]
> 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";

Re: sourcing one perl file from another

am 22.10.2007 16:25:17 von Ted Zlatanov

On Mon, 22 Oct 2007 05:08:58 -0500 "Mumia W." wrote:

MW> On 10/22/2007 04:52 AM, kc wrote:
>> [...]
>> 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

Re: sourcing one perl file from another

am 22.10.2007 16:29:45 von Ted Zlatanov

On Mon, 22 Oct 2007 09:52:31 -0000 kc wrote:

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

Re: sourcing one perl file from another

am 22.10.2007 23:10:28 von kc

Thanks Ted and Mumia, that did the trick!

Many thanks,
Kelvin

On Oct 23, 12:29 am, Ted Zlatanov wrote:
> On Mon, 22 Oct 2007 09:52:31 -0000 kc wrote:
>
> 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