SPUG: parsing a config file
El JoPe Magnifico
jope-spug at n2h2.com
Sat Jan 8 14:42:50 CST 2000
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
More information about the spug-list
mailing list