hotshot has asked for the wisdom of the Perl Monks concerning the following question:
Hi guys !
A little problem. I have a parser (not mine) for a configuration file (smb.conf if someone knows). this file as from the format:
anyone has an idea ?
Hotshot
A little problem. I have a parser (not mine) for a configuration file (smb.conf if someone knows). this file as from the format:
The problem is when I have something like this:[name1] key1 = value1 key2 = value2 ... [name2] key1 = value1 key2 = value2 ... # and so on
as you can see name2 has no values, this thing is ok (default values are taken), but the parser I have doesn't return it, here is it's code:[name1] key1 = value1 key2 = value2 ... [name2] [name3] key1 = value1 key2 = value2 ...
I can see the problem, no hash entry is opened if it didn't find any key=value pairs, so I tried adding something likesub smbconf_parse { my $smbconf = shift; my %smbconf; my $share = ''; if (! open(SMB, $smbconf)) { warn "Couldn't read smbconf file $smbconf\n"; warn "$!\n"; return 0; } while (<SMB>) { s/^\s+//g; s/\s+$//g; next if (/^$/); next if (/^\#/); next if (/^\;/); if (/^\[(.*)\]/) { $share = $1; ####### } else { my ($key, $value) = (/^(.*) ?\= (\S.*)/); $key =~ s/\s+$//; if ($value =~ /^\"(.*)\"$/) { $smbconf{$share}{$key} = $1; } elsif ($value =~ /\,/) { my @value = split(/\,/, $value); $smbconf{$share}{$key} = [ @value ]; } else { $smbconf{$share}{$key} = $value; } } } close SMB; return \%smbconf; }
right after the line with $share = $1;, but that seemed to mess the whole parsing.$smbconf{$share} = ''; # just to open the entry
anyone has an idea ?
Hotshot
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: hash reference
by Zaxo (Archbishop) on Feb 06, 2002 at 08:14 UTC | |
Re (tilly) 1: hash reference
by tilly (Archbishop) on Feb 06, 2002 at 08:35 UTC | |
Re: hash reference
by shotgunefx (Parson) on Feb 06, 2002 at 08:27 UTC | |
Re: hash reference
by CharlesClarkson (Curate) on Feb 06, 2002 at 08:29 UTC | |
Re: hash reference
by snowcrash (Friar) on Feb 06, 2002 at 08:35 UTC | |
Re: hash reference
by strat (Canon) on Feb 06, 2002 at 14:32 UTC |
Back to
Seekers of Perl Wisdom