jfroebe has asked for the wisdom of the Perl Monks concerning the following question:
I'm running into an annoyance that I find rather purplexing. Maybe it is the fact that the closer I get to my wedding, the more my brain is shutting down that I can't seem to see the problem. :-p
I open the STDERR descriptor in a local block and redirect it to a variable. The first time I call it, it works fine. The second time, I get an uninitiallized value error
Use of uninitialized value in open at ./test_stderr line 10.
#!/usr/bin/perl use strict; use warnings; sub test_stderr { my $output; { open local(*STDERR), '>', \$output; } print $output if $output; } test_stderr; test_stderr;
open local(*STDERR), '>', \$output; <--- line 10
The STDERR descriptor is getting closed but wouldn't wrapping it in local() only affect the STDERR within the block? This is obviously a scope question...
Any clues for the clueless me?
No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: stderr, local block and redirection
by Fletch (Bishop) on Sep 13, 2006 at 16:54 UTC | |
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 | |
|
Re: stderr, local block and redirection
by davido (Cardinal) on Sep 13, 2006 at 16:56 UTC | |
by jfroebe (Parson) on Sep 13, 2006 at 17:08 UTC |