Hi, I have a problem in reading an XML file that I want to include in a __DATA__ section. My first try was using the XML in the __DATA__ section as follows: my $cr = XMLin( *DATA ); After reading the XML::Simple docs, I saw it required an IO::Handle object, so I tried this:
my $xmldata = IO::Handle->new->fdopen(fileno(DATA),'r'); # print $xmldata->getline(); my $cr = XMLin( $xmldata );
which results in the error:

Unable to recognise encoding of this document at /usr/local/lib/perl5/site_perl/5.8.7/XML/SAX/PurePerl/EncodingDetect.pm line 96. Document requires an element Ln: 1, Col: 0

Which leads me to believe the $xmldata IO::Handle doesn't return any lines, however, If I uncomment the getline() line from the code above it prints a line, starting at character 12199 of my XML file.

I got 2 questions about this:

How can I read an XML file from a __DATA__ section (preferably with XML::Simple) ?

What magic happens with the DATA filehandle? Is some predefined number of characters read in from it at compilation time?

UPDATE: never mind question number 1, this solves my problem:

my $cr = XMLin( do { local $/ ; <DATA> } );
I'm still interested in what happend though.

In reply to __DATA__ in XML::Simple and/or IO::Handle by eXile

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.