In BASH, it is really easy to "read" preferences. For example, in
Mac OS X's /etc/rc startup script, it includes a file like so:
. /etc/rc.common
This file also includes /etc/hostconfig like so:
. /etc/hostconfig
So all startup items have access to the variables in /etc/hostconfig like:
SSHSERVER=-YES-
WEBSERVER=-YES-
My question is, can something similar be done in perl? Or do I have
to open, read, parse, then close the preference file?
--
Thanks,
James Reynolds
University of Utah
Student Computing Labs
james@scl.utah.edu
801-585-9811
Drieux - 24 Oct 2003 18:22 GMT
> In BASH, it is really easy to "read" preferences.
[..]
> My question is, can something similar be done in perl?
> Or do I have to open, read, parse, then close the preference file?
I'm not sure quite what bash is offering you for the 'read'
but it will still need to
open
read
parse
close
a preference file.
you really merely need a sub like:
which given a config_file name will return a reference to the hash
of stuff in that config file.
#------------------------
#
sub apple_config_file_parser
{
my ($file_name) = @_;
open(FD, $file_name) or die "unable to open $file_name: $!";
my $ref;
while(<FD>)
{
chomp;
s/#.*//;
if( /(.*)=(.*)/)
{
$ref->{$1} = $2;
}
}
close(FD);
$ref;
} # end of apple_config_file_parser
ciao
drieux
---