SPUG: parsing a config file

Todd Wells toddw at wrq.com
Mon Jan 10 21:18:32 CST 2000


Oh boy, will the thread ever die?  Well, El Jope Magnifico has brought up an
important issue I haven't dealt with and I'm hoping you SPUGgers can give me
a hand once again.  

>> One last item: You should consider escaping special characters and
>> adding surrounding quotes to your keys and values.  You could get
>> bitten hard if at some point one of perl's reserved words gets used
>> for either.

Can some experienced soul give me an easy approach to this?  After I read in
this data and manipulate it, it has to be written back to a file, so any
quotes or special characters that actually end up in the value will need to
be removed when written back to the file (if that's even an issue, which I
suspect it's not).

If you haven't been following the thread, here's the parsing code and some
example data:

         while ($line = <CONFIG>)
         {       
                 $line =~ s/=/=>/g;
                 $line =~ s#\;#\,#g;
                 $line =~ s#\(\)#""#g;
                 $line =~ s#\((.+)\)#\[$1\]#;
                 $config_data .= $line;
         }       
         $line .= ";";    
         eval $config_data;


#**** data below

{
    Domain = {
        servers = (beluga,toddw2,150.215.141.11);
        status = Enabled;
    };
    Log = {
        easLogLevel = Standard;
        log = On;
    };
    Model = {
        modelPath = "~/My/Models";
        models = {CCSDemo = { name = CCSDemo; pool = 1; max = 1; }; };
    };
    Restart = {
        Condition = 1;
        Enabled = YES;
        RestartTime = {
            CalendarFormat = "%d/%m/%Y %I:%M %p";
            FromTime = "18/07/1997 03:41 AM";
            ToTime = "18/07/1997 05:16 AM";
        };
        Schedule = 1;
    };
    Security = {
        administrator = Administrators;
        domain = DOMAIN;
        manager = Users;
        security = Off;
        user = Users;
    };
    Session = {
        idleTime = 100000;
        inactivityTimeout = 100000;
        maxSessions = 200;
      };
    SessionPool = {CCSDemo = {Entity = SignonPanel; Model = CCSDemo;
ModelVars = ({}); }; };
}

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list