On Tue, Jun 12, 2007 at 07:26:59PM -0700, Michael Higgins wrote:
> Like this:
>
> DEBUG = OFF
> THRESHOLD = 4
> SERVER = .
> USER = BATCH
> PASSWORD = PASSWORD
> Over Write = OVER WRITE
> BATCH TASK{
> TASK NAME = The Task
> SLEEP TIME{
> SECOND = 10
> }
> }
> . . .
>
> and similar. This first '{' starts nested data structures like above. They
> all match up.
If they are all on separate lines then you could do something like this:
You would have to handle blank values differently, and if there can be
more than one key with the same name the last one wins.
This was just a really quick hack so you probably want to expand on it.
#!/usr/bin/perl
use strict;
use warnings;
my $data = Parse();
use Data::Dumper;
print Dumper $data;
sub Parse
{
my %data;
while (<DATA>) {
chomp;
s/(^\s+)|(\s+$)//g;
my ($key, $value) = split /\s*=\s*/;
if ($value) {
$data{$key} = $value;
} elsif ($key =~ s/\s*{$//) {
$data{$key} = Parse();
} elsif (/^}$/) {
return \%data;
} else {
warn "Invalid line ($.): $_\n";
}
}
return \%data;
}
__DATA__
TEST=1
FILE=myfile
SUB{
SUBSTUFF = 12345
SUBMORE = 54321
SUBSUB {
1234 = abc
}
EMPTYSUB{
}
}
--
andrew - ICQ# 253198 - Jabber: [EMAIL PROTECTED]
BOFH excuse of the day: permission denied
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs