Re: Parsing of blocks (e.g. foo { bar })
From: Brian Harnish (bharnish_at_technologist.com)
Date: 10/30/03
- Next message: Bill: "Re: multiline regular expression, is it possible?"
- Previous message: Greg G: "Need help with OCIDefineObject"
- In reply to: Tor Houghton: "Parsing of blocks (e.g. foo { bar })"
- Next in thread: Tor Houghton: "Re: Parsing of blocks (e.g. foo { bar })"
- Reply: Tor Houghton: "Re: Parsing of blocks (e.g. foo { bar })"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 30 Oct 2003 15:16:30 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thu, 30 Oct 2003 12:36:39 +0000, Tor Houghton wrote:
> Hi,
>
> I'm wondering if there is a more elegant way of parsing "blocks" of data.
[snip]
> 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 :-> )
You didn't really say how you wanted to handle this condition. Is it a
valid condition, or can your program just abort?
If you need to handle that condition, then instead of using the scalar
".."'s flag, use a nesting counter:
my $nest = 0;
while(<CONF>) {
$nest++ if (/(\S+)\s*\{/);
$nest-- if (/\}/);
if($nest == 1) { # Or, $nest >= 1
# Handle conditions.
}
}
Actually, thinking about it, aborting would use very similar logic.
- Brian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/oStgiK/rA3tCpFYRAjpzAKCDOI/WgKFUnNmnG7Bf4hNuTSg1qQCgxvWm
vrQkYrxLEaFNq65GM8MwIEI=
=3Yc1
-----END PGP SIGNATURE-----
- Next message: Bill: "Re: multiline regular expression, is it possible?"
- Previous message: Greg G: "Need help with OCIDefineObject"
- In reply to: Tor Houghton: "Parsing of blocks (e.g. foo { bar })"
- Next in thread: Tor Houghton: "Re: Parsing of blocks (e.g. foo { bar })"
- Reply: Tor Houghton: "Re: Parsing of blocks (e.g. foo { bar })"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|