in reply to Re: Re: Re: Parsing XML into a Hash
in thread Parsing XML into a Hash

"So what's wrong with that?"

Murphy will rear 'is ugly and head and next thing you know the XML will need be nested:
... <name> <first_name>Foo</first_name> <last_name>Bar</last_name> </name> ...
and attributes will be needed:
... <name part="first">John</name> <name part="last">Smith</name> ...
.. and more goodies waiting around the corner for anyone trying to write a parser that has never written any kind of compiler. I personally do not like to waste valuable time reinventing a wheel that only takes a few moments to install. You download it, you install it, you write stuff that matters and you don't worry about the issues i pointed out.

But .... IF and if that XML will never get more complicated that originally posted, then your code should suffice. However, a "real" XML parser does not 10 lines of code make, just take a look at XML::SAX::PurePerl. ;)

UPDATE:
Now you are just being silly graff. My whole point was that one shouldn't have to worry "as the need arises". Not when all you do is install a CPAN module (i like BrowserUk's suggestion: XML::Parser::Lite). mcogan1966 - you are in for a bumpy ride. Please take BrowserUk's suggestion. If you really are "Lord and Master", then use a module for this. But don't take my word for it (besides, what could i possibly know about projects that never finish because of red tape?) just wait till Murphy gets you. ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^5: Parsing XML into a Hash
by graff (Chancellor) on Nov 04, 2003 at 04:45 UTC
    Nested schmested! Those examples still look like a flat table to me. ;^) ... Seriously, this could just mean changing the names/regex patterns to identify the tags that really matter, including their attributes, as the need arises.

    Granted, the poor soul might someday have to face elements whose attributes and/or content structure show significant variability, or even -- God help him -- recursion. Then he's really not in flat-table-land anymore, and it's time to bring in the right tools (a real parser).

      Nested schmested! Those examples still look like a flat table to me.

      And they are.
      And they will continue to be.
      I am Lord and Master of this code.
      All it has to do is what they want it to do.
      I get to make the design decision.
      So, if it's a flat-file XML format, then that's what it is.
      And nothing goes into that file without my approval now.
      *insert evil laugh here*