Приглашаем посетить
Грин (grin.lit-info.ru)

Q&A

Previous Table of Contents Next

Q&A

Q1:

XML::Simple isn't reading my XML correctly! I'm getting errors about well-formed documents. What does this mean?

A1:

XML documents should be well-formed. This means that there are matching opening and closing tags for every element, that they're correctly nesting, attributes are quoted, and that there are no stray XML characters inside of the element's data. If your XML document violates any of these rules, all XML parsers are supposed to stop. That's one big difference between reading XML with a regular expression and with a real parser. Fix your XML document and try again!

Q2:

XML::Simple isn't returning hashes where I'd expect it to, and I can't figure out the document structure.

A2:

Use Data::Dumper as shown in Listing 19.8 to figure out what the structure really looks like. XML::Simple's handling of various elements (should it create a hash or an array here?) can be tweaked by using arguments to XMLin.

Q3:

I've been given a binary file to deal with in Perl. What are my options?

A3:

Binary data's not so bad to deal with in Perl, it's just unusual and unique enough that each case has to be dealt with individually. Functions that can be useful in decoding binary data are unpack, substr, and of course, regular expressions.

    Previous Table of Contents Next