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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: peek at STDIN, to determine data type and then pass STDIN to a parser
by aral (Acolyte) on Jan 06, 2015 at 14:42 UTC

    :(

    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)

A reply falls below the community's threshold of quality. You may see it by logging in.