parsing an apache-like conf-file
I have a proxy-application that I want to make as generic as possible by using configure files. I have a configure file that looks something like: ko-web.ei.sigma.se info.ei.sigma.se info.ei.sigma.se Order deny, allow Deny All Allow nisse.ei.sigma.se Is there a standard way of reading such file into a perl-structure (hash or object)? I have solved it by just reading the file and use regexps to filter the information. It works, but the code will be hard to maintain. thanks for listening, Jonas Nordstrom
Re: parsing an apache-like conf-file
On Wed, 31 Jan 2001, Jonas Nordström wrote: > I have a proxy-application that I want to make as generic as possible by > using configure files. > I have a configure file that looks something like: > > > >ko-web.ei.sigma.se > > > > > info.ei.sigma.se > > > info.ei.sigma.se > > Order deny, allow > Deny All > Allow nisse.ei.sigma.se > stodjande.ei.sigma.se > lopande.ei.sigma.se > css.ei.sigma.se > > > > Is there a standard way of reading such file into a perl-structure (hash or > object)? > I have solved it by just reading the file and use regexps to filter the > information. It works, but the code will be hard to maintain. Looks like a job for XML::Simple. -- /||** Director and CTO ** //||** AxKit.com Ltd ** ** XML Application Serving ** // ||** http://axkit.org ** ** XSLT, XPathScript, XSP ** // \\| // ** Personal Web Site: http://sergeant.org/ ** \\// //\\ // \\
Re: parsing an apache-like conf-file
On Wed, 31 Jan 2001, Matt Sergeant wrote: > On Wed, 31 Jan 2001, Jonas Nordström wrote: > > > I have a proxy-application that I want to make as generic as possible by > > using configure files. > Looks like a job for XML::Simple. Or Config::General::Extended. -- steven 1;
Re: parsing an apache-like conf-file
Jonas Nordström wrote: > > I have a proxy-application that I want to make as generic as possible by > using configure files. > I have a configure file that looks something like: > > >ko-web.ei.sigma.se > > > > > info.ei.sigma.se > > > info.ei.sigma.se > > Order deny, allow > Deny All > Allow nisse.ei.sigma.se > stodjande.ei.sigma.se > lopande.ei.sigma.se > css.ei.sigma.se > > > > Is there a standard way of reading such file into a perl-structure (hash or > object)? > I have solved it by just reading the file and use regexps to filter the > information. It works, but the code will be hard to maintain. > > thanks for listening, > Jonas Nordstrom Since you are talking about parsing, this reminds me about my project. It's a token analyzer. If you are faced with the task of scanning/parsing files, for instance, configuration ones, maybe you'll want to give a token at my code. Some features of The Ant Scanner (ASC for short). (and remeber, you may call this features as bugs as you may like) . Performance: Extremely FAST, . Reliability: Error recovery option, . Flexibility: you are on the control, ALWAYS, . Token Size: ASC put no limitation on token size, . Design: Carefully designed, to be used builtin your app. It's very small, no external linkage required. . Requires you to define you token types and DFA by HAND = dirty work, but leap you to great control over what the asc will reconize. Anyone who may wish to take a closer look on what i have written, send me an email and i will send the tarball. I hope this helps.
Re: parsing an apache-like conf-file
On Wed, 31 Jan 2001, Matt Sergeant wrote: > Looks like a job for XML::Simple. Except we've had no end of trouble with it dumping core in a mod_perl environment. My XML::Tree is far faster, much smaller, and doesn't dump core: http://homepage.mac.com/pauljlucas/software/xml_tree/ - Paul
Re: parsing an apache-like conf-file
On Wed, 31 Jan 2001, Paul J. Lucas wrote: > On Wed, 31 Jan 2001, Matt Sergeant wrote: > > > Looks like a job for XML::Simple. > > Except we've had no end of trouble with it dumping core in a > mod_perl environment. Thats well explained in the AxKit FAQ: http://axkit.org/faq.xml (and patches for mod_dav to enable you to build it in a non-expat apache are in the axkit download directory). > My XML::Tree is far faster, much smaller, and doesn't dump core: > > http://homepage.mac.com/pauljlucas/software/xml_tree/ But its not as simple to use as XML::Simple, which is perfect for these sorts of things :-) -- /||** Director and CTO ** //||** AxKit.com Ltd ** ** XML Application Serving ** // ||** http://axkit.org ** ** XSLT, XPathScript, XSP ** // \\| // ** Personal Web Site: http://sergeant.org/ ** \\// //\\ // \\
Re: parsing an apache-like conf-file
On Wed, 31 Jan 2001, Matt Sergeant wrote: > > My XML::Tree is far faster, much smaller, and doesn't dump core: > > > > http://homepage.mac.com/pauljlucas/software/xml_tree/ > > But its not as simple to use as XML::Simple, which is perfect for these > sorts of things :-) What could be simpler than: $xml = XML::Tree->new( 'foo.xml' ); $ref = $xml->as_array(); ? - Paul
Re: parsing an apache-like conf-file
On Wed, 31 Jan 2001, Paul J. Lucas wrote: > On Wed, 31 Jan 2001, Matt Sergeant wrote: > > > > My XML::Tree is far faster, much smaller, and doesn't dump core: > > > > > > http://homepage.mac.com/pauljlucas/software/xml_tree/ > > > > But its not as simple to use as XML::Simple, which is perfect for these > > sorts of things :-) > > What could be simpler than: > > $xml = XML::Tree->new( 'foo.xml' ); > $ref = $xml->as_array(); Its what's in $ref thats complex (or more complex than XML::Simple), see the man page for XML::Simple. -- /||** Director and CTO ** //||** AxKit.com Ltd ** ** XML Application Serving ** // ||** http://axkit.org ** ** XSLT, XPathScript, XSP ** // \\| // ** Personal Web Site: http://sergeant.org/ ** \\// //\\ // \\
Re: parsing an apache-like conf-file
On Wed, 31 Jan 2001, Matt Sergeant wrote: I wrote: > > What could be simpler than: > > > > $xml = XML::Tree->new( 'foo.xml' ); > > $ref = $xml->as_array(); > > Its what's in $ref thats complex (or more complex than XML::Simple), see > the man page for XML::Simple. Yes, but I think XML::Simple got the data structures generally wrong and has too many options. A user of XML::Simple looking at his own code a few weeks later, or, worse, somebody else's, always has to (re)figure out what options were given to it at data-structure creation time and what that really means in terms of the data structure you get back. This means you're always having to look at the man page. You may think XML::Simple results in simpler data structures; however, the mental energy expended to refigure stuff out makes XML::Simple more complex in the long term. Aside from being slow, this is another complaint about it. In contrast, the data structure you get back from XML::Tree is always the same. As Antoine de Saint-Exupery remarked: A designer knows he has arrived at perfection not when there is no longer anything to add, but when there is no longer anything to take away. - Paul
Re: parsing an apache-like conf-file
On Wed, 31 Jan 2001, Paul J. Lucas wrote: > You may think XML::Simple results in simpler data structures; > however, the mental energy expended to refigure stuff out makes > XML::Simple more complex in the long term. Aside from being > slow, this is another complaint about it. I've never heard anyone complain about it being slow. I'm not saying XML::Tree isn't faster, just that I've never heard that complaint about XML::Simple, simply because people don't use it for parsing large files, just small config files. The only reference I can find on Google that says XML::Simple and slow are the XML::Simple man page talking about eval being slow (or not, depending on the eval type). Deja has no references at all. I guess maybe your measures are different to, erm, the rest of the internet's :-) As for being more complex to use, I would say XML::Simple's popularity speaks for itself (especially when compared with say XML::DOM or Grove or even XPath). -- /||** Director and CTO ** //||** AxKit.com Ltd ** ** XML Application Serving ** // ||** http://axkit.org ** ** XSLT, XPathScript, XSP ** // \\| // ** Personal Web Site: http://sergeant.org/ ** \\// //\\ // \\
Re: parsing an apache-like conf-file
On Wed, 31 Jan 2001, Matt Sergeant wrote: > I've never heard anyone complain about it being slow. I'm not saying > XML::Tree isn't faster, just that I've never heard that complaint about > XML::Simple, simply because people don't use it for parsing large files, just > small config files. Or perhaps they don't need to handle hundreds of thousands of hits a day, i.e., on the scale of eBay. > I guess maybe your measures are different to, erm, the rest of the internet's The benchmark I used is right on my web page. > As for being more complex to use, I would say XML::Simple's popularity speaks > for itself (especially when compared with say XML::DOM or Grove or even > XPath). Or, until now, there wasn't something better. - Paul