There is probably some annoying OS trickery that would cause this "seek on STDIN" technique to fail on certain OSes and under certain conditions, but it tested properly where I wrote it. I hope you are as lucky.my $c=0; while($c<3){ my $l=<STDIN>; print "## $c ## $l"; $c++; } seek(STDIN,0,0); while(<STDIN>){ print ".... $_"; }
Another idea would be build a "rewindable filehandle" with either a tied filehandle or a subclass of the IO::File module that would hold a "back buffer" and have a rewind function. It's too late on a friday for me to come up with any more details of exactly how this would be done, but I think it is doable. Of course, this would only be necessary if the seek method doesn't work for you.
There is always the less-elegant solution of dumping all of STDIN out to a temp file, opening the temp file, grabbing the first n lines for your pre-processing, closing/reopening (or seeking back to BOF) the tempfile, and passing that handle to MIME::Parser. This is easier to code than the advanced approaches I mentioned above, but will really increase disk IO and just feels icky.
In reply to Re: re-start reading from stdin?
by lhoward
in thread re-start reading from stdin?
by Punto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |