bill wrote:
> I run into the need to do this *all* the time, but I have not come
> up with a solution. This need arises almost invariably during the
> debugging of a CGI script. At the beginning of the run I want to
> inspect all the input that the CGI script will read from STDIN,
> but I want to then "restore" this input back to the STDIN stream
> so that execution/debugging session can proceed normally.
>
> I *think* the best solution would be to slurp all the text into a
> lexical
>
> my $input = do { local $/; <STDIN> };
> # {
> # open my $out, ">debugging_data" or die "$!\n";
> # print $out $input;
> # close $out or die "$!\n";
> # }
>
> associate this lexical with an IO::Scalar handle
>
> my $SH = IO::Scalar->new(\$input);
>
> and then redefine STDIN so that it points to this IO::Scalar.
> *This* is the part that I just can't figure out. Following what
> I see in tutorials and books, I have tried
>
> open(STDIN, "<&$SH") or die "$!\n";
you probably want to open it on the file descriptor (take a look at fileno):
redwood 24357 $ perl -le 'open IN,"</etc/passwd";open STDIN,"<&".fileno(IN);
$a=<STDIN>;
print "$a\n"'
root

:0:1:Super-User:/:/sbin/sh
*but* what you probably want to be doing is using the CGI module to
parse your cgi parameters. You can initialize this from a FileHandle or
IO::File object as necessary, so you could slurp STDIN into a lexical
variable, create an IO::String object from this, dump out the results
and then initialize the CGI object from this. Also check out
restore_parameters in the CGI module.
It is highly likely that I am missing something obvious here.
Mark