Excellent solution as well - I just tested it and it worked out of the box like this:
use FileHandle::Unget; my $fh = FileHandle::Unget->new(\*STDIN) or die "Cannot open filehandle: $!"; my $testline = <$fh>;; $fh->ungets($testline); print "$.: $testline"; for (my $i = 0; $i < 3; $i++) { $testline = <$fh>; print "$.: $testline"; }
Output for "cat xmlfile | ./perscript.pl" is:
1: <?xml version="1.0" encoding="UTF-8"?> 1: <?xml version="1.0" encoding="UTF-8"?> 2: <MFOP> 3: <Basics>
Thank you very much! FileHandle::Unget is *the* answer to my original question.
@ikegami: Unfortunately, the install script (Makefile) for IO::Unread fails with error messages, and there seems to be no debian packet for it available in jessie - so I was not able to test this.
In reply to Re^2: peek at STDIN, to determine data type and then pass STDIN to a parser
by aral
in thread peek at STDIN, to determine data type and then pass STDIN to a parser
by aral
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |