Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Saving STDERR and displaying it later

by ikegami (Patriarch)
on Jul 04, 2006 at 01:10 UTC ( [id://559069]=note: print w/replies, xml ) Need Help??


in reply to Saving STDERR and displaying it later

eval BLOCK catches die. The following catches warnings and other uses of STDERR:

use v5.8.0; my $stderr; { open(local *STDERR, '>', \$stderr); warn("foo\n"); # no output } print STDERR ("\$stderr: $stderr"); # $stderr: foo

Together:

use v5.8.0; my $stderr; eval { open(local *STDERR, '>', \$stderr); warn("foo\n"); # no output die("bar\n"); # no output }; print STDERR ("\$stderr: $stderr"); # $stderr: foo die($@) if $@; # bar

In earlier version of Perl, I think you can use IO::Scalar to do:
tie *STDERR, 'IO::Scalar', \$stderr;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://559069]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found