Parsing of blocks (e.g. foo { bar })
From: Tor Houghton (torh+news_at_removethisbitbeforethedot.bogus.net)
Date: 10/30/03
- Next message: Brian McCauley: "Re: fork process to handle fifo input"
- Previous message: Randal L. Schwartz: "Re: In search of elegant code: inverting a string"
- Next in thread: Brian Harnish: "Re: Parsing of blocks (e.g. foo { bar })"
- Reply: Brian Harnish: "Re: Parsing of blocks (e.g. foo { bar })"
- Reply: David K. Wall: "Re: Parsing of blocks (e.g. foo { bar })"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 30 Oct 2003 12:36:39 +0000
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
- Next message: Brian McCauley: "Re: fork process to handle fifo input"
- Previous message: Randal L. Schwartz: "Re: In search of elegant code: inverting a string"
- Next in thread: Brian Harnish: "Re: Parsing of blocks (e.g. foo { bar })"
- Reply: Brian Harnish: "Re: Parsing of blocks (e.g. foo { bar })"
- Reply: David K. Wall: "Re: Parsing of blocks (e.g. foo { bar })"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|