"Beau E. Cox" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi -
>
> Perl is not like a typical compiled language, for example, c/c++.
> It really doesn't have the typical 'include' functionality.
> The 'use' and 'require' keywords are for 'including' perl
> modules (normally with the .pm suffix) that reside in the
> @INC path (type 'perl -V' to see your @INC path). Modules
> normally are 'packages' that are coded to address a particular
> programming tasks not native to the perl core. You probally are
> not looking to code a module for you purposes.
>
> One way I have used to accomplish something similar to what you
> are trying to do is to code a 'configuration' file that returns
> a hash reference:
>
> {
> model => "blah, blah, blah...",
> color => "red",
> serial_number => 8997234,
> };
>
> and then involk the configuration using the string
> form to eval:
>
> my $options;
> open CONF, "conf.file" or die "...',
> {
> undef $/; # slurp the file
> my $data = <CONF>;
> $options = eval $data;
> $@ && die "syntax error...";
> close CONF;
> }
>
> print "$options->{model}\n";
> print "$options->{color}\n";
> print "$options->{serial_number}\n";
>
> Aloha => Beau.
This is a fine solution, but I really recommend avoiding the eval.
#!/usr/bin/perl -w
use strict;
use My::Config;
my($config) = My::Config::getConfig();
print( $config->{model} );
now in the file @INC/My/Config.pm
package My::Config;
use strict;
sub getConfig {
return( {
model => "blah, blah, blah...",
color => "red",
serial_number => 8997234,
});
}
1;
Todd W.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]