Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Parsing multi-line blocks

by sschneid (Deacon)
on Nov 13, 2007 at 16:01 UTC ( [id://650519]=perlquestion: print w/replies, xml ) Need Help??

sschneid has asked for the wisdom of the Perl Monks concerning the following question:

Monks, Is there any easy way to parse multi-line blocks (ie: configuration files)? I assume there are existing modules to do this, but my (admittedly weak) CPAN search skills haven't come up with anything. Learning Parse::RecDescent seems like it may be overkill in this situation (right?)... In any case, syntax of the file I'm attempting to parse is:
$type $key { $type2 $data $type2 $data }
e.g.
self 192.168.49.167 { netmask 255.255.255.0 unit 1 floating enable vlan public allow default } pool EIS-ORMI-Pool { lb method observed monitor all ORIM_https_monitor members 192.168.11.192:6003 192.168.11.173:6003 10.125.11.213:6003 10.125.11.214:6003 }
Thanks in advance!
-s.

Replies are listed 'Best First'.
Re: Parsing multi-line blocks
by cdarke (Prior) on Nov 13, 2007 at 16:20 UTC
    It depends what you mean by 'parse'. I'm guessing that you wish to read each block as one record, then split the fields. Just set local $/='}'; then read the file in the usual way: each block will be one record. Then you can split around "\n" to get the fields.
      Thanks! I'd begun building something that parsed tokens based on $/, but didn't know if there was already a module somewhere that would save me from having to reinvent wheels, etc!
Re: Parsing multi-line blocks
by toolic (Bishop) on Nov 13, 2007 at 16:27 UTC
    You could consider a CPAN module such as Config::General. Take a look, and see if it matches your needs.
      I'll take a look at it! Thanks!
Re: Parsing multi-line blocks
by grinder (Bishop) on Nov 13, 2007 at 18:04 UTC

    This is what? a configuration file for a router or a some sort of network device?

    Have you tried searching for the product name or company name, to see if anyone has already written something that deals with it? It might not be on CPAN: use a web search as well.

    • another intruder with the mooring in the heart of the Perl

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://650519]
Approved by grep
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-28 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found