From: Logan Capaldo Date: 2006-10-06T10:28:07+09:00 Subject: Re: Parsing files On Fri, Oct 06, 2006 at 10:15:12AM +0900, barjunk wrote: > I'm new to ruby and one of the first projects I am trying to tackle is > parsing a file > with this sort of format: > > zone "localdomain" IN { > type master; > file "localdomain.zone"; > allow-update { none; }; > }; > > or host devicename-1 { > hardware ethernet 00:10:51:61:74:FF; > fixed-address 192.168.0.15; > } > > > The basic issue I'm working to resolve is how can I treat these > sections as "records". > > I know I could read the entire file into memory, but I was looking to > only deal with them > on a record by record basis. > > One thought was to read through the file and keep a hash of information > about where the > record starts and ends, then when I want to read a record, use that > reference to get the > data. > > Has anyone done something similar to this that I can use to learn how > to manage these > types of file formats? > > There won't be an issues with concurrent access at this point. > > These formats are found when using dhcp, freeradius, and nagios. I'm > sure there are others. > I would write a grammar and a recursive descent parser for files like these. Someone is bound to reply with some crazy regexp that works, but only they will ever understand it ;). > Mike >