in reply to stderr, local block and redirection
Try my $output = ""; instead. And you may actually want to print something to STDERR inside the block.
#!/usr/bin/perl use strict; use warnings; sub test_stderr { my $output = ""; { open local(*STDERR), '>', \$output; print STDERR "CATCH ME IF YOU CAN\n"; } print "\$output is '$output'\n" if $output; } test_stderr; print STDERR "I'm not caught\n";
Update: Gah, got a halfway version in my clipboard. Tweaked slightly.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: stderr, local block and redirection
by jfroebe (Parson) on Sep 13, 2006 at 17:07 UTC | |
by Fletch (Bishop) on Sep 13, 2006 at 17:43 UTC | |
by ikegami (Patriarch) on Sep 13, 2006 at 18:30 UTC | |
by jfroebe (Parson) on Sep 13, 2006 at 18:21 UTC |