SPUG: parsing a config file
Todd Wells
toddw at wrq.com
Mon Jan 10 20:13:56 CST 2000
Well, this method has worked out great, but I'm having a problem as a result
of this parentheses/square brackets issue.
Here's the deal, if I feed this data to the routine:
Domain = {
servers = (beluga,toddw2,150.215.141.11);
status = Enabled;
};
Then I get this data structure:
$config = HASH(0x2ff098)
'Domain' => HASH(0x282a0c)
'servers' => 'beluga'
'status' => 'Enabled'
'toddw2' => '150.215141.11'
This becomes a problem when after winding all of this config data into
nested hashes I have to unwind it back into a config file.
Would it better if I turn those parens into brackets? Or do you have some
other trick up your sleeve?
- Todd
<deletia>
undef $/;
my $line = <DATA>;
$line =~ s/=/=>/g;
$line =~ s/\;/\,/g;
$line =~ s/\(\)/""/g;
$line .= ";";
my $Config = eval $line;
-----Original Message-----
From: El JoPe Magnifico [mailto:jope-spug at n2h2.com]
Sent: Saturday, January 08, 2000 12:43 PM
To: Andrew Sweger
Cc: Todd Wells; Seattle Perl Users Group
Subject: Re: SPUG: parsing a config file
Not quite right, Mr. Sluggo! The trailing comma between the two closing
curly brackets does no harm. Look closer below, specifically the value for
$Config->{'Domain'}{'servers'} ...parentheses, rather than square brackets!
Because => is syntactically the same as a comma, that empty list collapses
in on itself, leaving you with three items in the list being assigned to
the %{$Config->{'Domain'}} hash, efffectively making the assigment...
Domain => {
servers => status,
Enabled =>
}
Hence the error below. My connection keeps dogging out on me, so I'll
leave it to someone else to add the line(s) to convert the parenthese to
square brackets.
-jp
On Fri, 7 Jan 2000, Andrew Sweger wrote:
> On Jan 7, 2000 @ 3:19pm, jimfl wrote:
>
>> $cdata = q($Config = );
>> while ($line = <DATA>) {
>> $line =~ s/=/=>/g;
>> $line =~ s/\;/\,/g;
>> $cdata .= $line;
>> }
>> $cdata .= ";";
>> eval $cdata;
>
> Oh, that's very nice. That's a beaut. But it's slightly flawed.
>
> Odd number of elements in hash assignment at (eval 5) line 1, <DATA> chunk
> 28.
> eval '$Config =
> {
> Domain => {
> servers => (),
^^^ *** here's the problem! **
> status => Enabled,
> },
> Log => {
> easLogLevel => Standard,
> log => On,
> },
> Restart => {
> Condition => 0,
> Enabled => NO,
> RestartTime => {
> CalenderFormat => "%d/%m/%Y %I:%M %p",
> FromTime => "18/07/1997 03:00 AM",
> ToTime => "18/07/1997 06:00 AM",
> },
> Schedule => 0,
> },
> Security => {
> administrator => Administrators,
> domain => MINE,
> manager => Users,
> security => Off,
> user => Users,
> },
> }
> ;'
> ^---- here
>
> It's that last comma. This works...
[...]
> ...but I'm not sure that chopping a comma out from between two closing
> braces will be enough (or it could go horribly wrong depending on what's
> in the data).
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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