in reply to Re^2: Can I seek in a command's piped output?
in thread Can I seek in a command's piped output?

Ah -- sorry, I didn't catch the issue about passing the pipe file handle to XML::Parser.

If the idea of using IO::Unread doesn't work out (though I expect it will do fine), there's also the possibility that you can use a script like the one I suggested, but instead of having two different subs in the dispatch table, you would have two different command lines -- one being your (separate) XML parser script invoked in a way to handle one type of stream, and the other(s) for handling the other type(s) of stream, and you just launch the right one as a subprocess:

my @holdem; my %dispatch = ( one => [ qw/my_parser --this_way/ ], two => [ qw/my_parser --that_way/ ], ); my $target; open( $pipe, "-|", "some_xml_generator" ); # not "ls", obviously while ( <$pipe> ) { if ( $target ) { print $target $_; } else { push @holdem, $_; my $decision = look_for_evidence( $_ ); if ( $decision =~ /one|two/ ) { open( $target, "|-", @{$dispatch{$decision}} ) or die "failed to launch: $dispatch{$decision}: $!\n"; print $target $_ for ( @holdem ); } } }
Your separate parser script uses the command line option to control how to set up event handlers for parsing.

(updated snippet to fix stupid mistakes, like forgetting to use a list for "command", "option" when opening the pipe to the parser script.)