in reply to Parsing XML in a __DATA__ Block

No <DATA> is not a filehandle, it is an instance of the readline operator - DATA is a filehandle - you will probably want to do:

my $parser = XML::LibXML->new(); my $xml = $parser->parse_fh(*DATA);

/J\

Replies are listed 'Best First'.
Re^2: Parsing XML in a __DATA__ Block
by mirod (Canon) on Jun 01, 2005 at 09:20 UTC

    Funny, I always use \*DATA, but plain *DATA works equally well. Is there any difference between the 2?

      \*DATA is a real reference (typeglob reference), *DATA is not (bare typeglob).

      Those definitions extracted from `perldoc perlsub' (look for \*).

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

      In most cases it doesn't matter, but it causes extra pain when you want to write a function that accurately needs to know "do I have a filehandle", like in File::Copy:
      my $from_a_handle = (ref($from) ? (ref($from) eq 'GLOB' || UNIVERSAL::isa($from, 'GLOB') || UNIVERSAL::isa($from, 'IO::Handle')) : (ref(\$from) eq 'GLOB'));
Re^2: Parsing XML in a __DATA__ Block
by loris (Hermit) on Jun 01, 2005 at 09:23 UTC

    Many thanks to you and mirod for the swift depuzzlement.

    loris

Re^2: Parsing XML in a __DATA__ Block
by loris (Hermit) on Jun 02, 2005 at 10:49 UTC

    Actually, one thing is still puzzling me.

    When I have

    __DATA__ ... XML here ... __END__

    I get the error

    Entity: line 13: parser error : Extra content at the end of the docume +nt __END__

    Shouldn't __END__ be recognised as not being part of the contents of the __DATA__ block?

    loris

      __END__ and __DATA__ are virtually synonyms, so that doesn't sound too practically feasable to me. Besides, what if you do want a line "__END__" inside your data, what then?

      Perhaps you should look into Inline::File.

      No

      /J\