Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / October 2003



Tip: Looking for answers? Try searching our database.

Reading preferences

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James Reynolds - 23 Oct 2003 19:15 GMT
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

---
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.