jeanluca has asked for the wisdom of the Perl Monks concerning the following question:
Output:use strict; use warnings; my $out ; { local *STDOUT ; local *STDERR ; open STDOUT, '>>', \$out or die "Can't open STDOUT: $!"; # line 28 open STDERR, '>>', \$out or die "Can't open STDERR $!"; # line 29 select STDOUT; $| = 1; # make unbuffered select STDERR; $| = 1; # make unbuffered print "message1\n" ; warn "error1\n" ; print "message2\n" ; } print "Result: $out \n" ;
So, line 29 has a problem while line 28 has not, any suggestions why?Use of uninitialized value in open at ./t2.pl line 29. Result: message1 error1 message2
In the browser I get nothing(blank), but running it from the commandline I get what I expected:use CGI qw(:standard append add_parameter); use strict ; use warnings ; print CGI::header() ; my $out ; { local *STDOUT ; local *STDERR ; open (STDOUT,">>", \$out) ; open (STDERR,">>", \$out) ; select STDOUT; $| = 1; # make unbuffered select STDERR; $| = 1; # make unbuffered print "message1\n" ; warn "error1\n"; print "message2\n" ; } print "Result: $out\n";
But if I remove the line select STDERR; $| = 1; everything works fine in the browser too!$ ./t2.pl Content-Type: text/html; charset=ISO-8859-1 Use of uninitialized value in open at ./t2.pl line 29. Result: message1 error1 message2
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: problems redirecting STDOUT and STDERR to a $variable
by kyle (Abbot) on Feb 15, 2008 at 13:31 UTC | |
Re: problems redirecting STDOUT and STDERR to a $variable
by philcrow (Priest) on Feb 15, 2008 at 16:02 UTC | |
by ikegami (Patriarch) on Feb 15, 2008 at 18:03 UTC |