T
Tor Houghton
Hi,
I'm wondering if there is a more elegant way of parsing "blocks" of data.
I have a configuration file, thus:
# comment
some.host.name {
; another comment
/etc/hostname.fxp0
/etc/hosts
/etc/mail
}
And I currently parse this using the following code:
while(<CONF>) {
next if(/^\s*(\#|
|^\s*$/);
if(m#(\S+)\s+{# .. m#}#) {
$HOST=$1 if $1;
if(!/\{|\}/) {
print "add: $HOST ",$_;
}
}
}
Before I go "all out" and complete this section of the code using the
above technique, I was wondering if there was other (better) ways of doing
this (for one, I'm not sure how to catch out any errors in the file, for
instance:
some.host.here {
another.host {
/usr
/opt
}
/etc
/var/mail
}
... here the current code fails miserably. Mind you, I'm probably the only
one going to use this, so that may not be such a big deal :-> )
Thanks!
Tor
I'm wondering if there is a more elegant way of parsing "blocks" of data.
I have a configuration file, thus:
# comment
some.host.name {
; another comment
/etc/hostname.fxp0
/etc/hosts
/etc/mail
}
And I currently parse this using the following code:
while(<CONF>) {
next if(/^\s*(\#|
if(m#(\S+)\s+{# .. m#}#) {
$HOST=$1 if $1;
if(!/\{|\}/) {
print "add: $HOST ",$_;
}
}
}
Before I go "all out" and complete this section of the code using the
above technique, I was wondering if there was other (better) ways of doing
this (for one, I'm not sure how to catch out any errors in the file, for
instance:
some.host.here {
another.host {
/usr
/opt
}
/etc
/var/mail
}
... here the current code fails miserably. Mind you, I'm probably the only
one going to use this, so that may not be such a big deal :-> )
Thanks!
Tor