On Thursday, Oct 23, 2003, at 11:15 US/Pacific, James Reynolds wrote:
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
---