Untested:
Now if you don't destroy anything, reading from STDIN gives you what is already in $data which is what was in STDIN.use IO::Scalar; my $data; tie *HACK, 'IO::Scalar', \$data; print HACK <STDIN>; tied(*HACK)->setpos(0); *STDIN = *HACK;
UPDATE
The idea was good but apparently copying tied stuff like that does not maintain the tie. (I shoulda known that, sorry.) Try this code instead:
I tested this by addinguse IO::Scalar; $data = join '', <STDIN>; my $s; tie *STDIN, 'IO::Scalar', \$s; print STDIN $data; tied(*STDIN)->setpos(0);
after it, running it, and typing into it.print $data; print <STDIN>;
My apologies for the initial mistake.
In reply to Re (tilly) 1: How to preserve the value of STDIN
by tilly
in thread How to preserve the value of STDIN
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |