in reply to Re: peek at STDIN, to determine data type and then pass STDIN to a parser
in thread peek at STDIN, to determine data type and then pass STDIN to a parser

:(

Luck has it that XML::Twig actually does not need the XML Header line to correctly parse a file - so in my current problem, I can actually identify the proper XML header and then pass the rest of STDIN to the control of the parser.

However, if there's nothing fundamentally problematic with peeking at pipes, that's a functionality that would bring a lot to developers if introduced and would at the same time be 100% downward compatible..

I suppose the fundamental problem is cross-patform-compatibility... But one has to start somewhere, introducing new functionality :) However, this seems to be a problem on operating system level, not perl.

Still happy for more inputs - otherwise I have a workaround:

use XML::Twig; # needs libxml-twig-perl my $line = <>; if (isXmlHeader ($line)) { my $t = XML::Twig->new(); $t->parse (\*STDIN); }

("isXmlHeader" evaluates $line for being a correct XML document header tag)

  • Comment on Re^2: peek at STDIN, to determine data type and then pass STDIN to a parser
  • Download Code