On 5/7/07, Karyn Williams <[EMAIL PROTECTED]> wrote:
I have this script I have been working on where I need to redirect STDOUT and STDERR to files at the beginning of the script and then back to default (terminal) at the end of the script. I found an example on-line and used it and it works, however it generates a warning when running my script. I would prefer to make that warning go away. This is the output of the script:
IIRC, you may get rid of these warnings with at least two different solutions: (1) cheat, and tell Perl not to warn on things it "thinks" to have been used only once no warnings "once"; # would be enough
alum# ./match.pl Name "main::OLDERR" used only once: possible typo at ./match.pl line 38. Name "main::OLDOUT" used only once: possible typo at ./match.pl line 37.
Because the warnings are just that: the Perl interpreter thinks OLDERR and OLDOUT were used just once, because they show up in the open statements and again when you restore the STDOUT and STDERR.
open(STDOUT, ">&OLDOUT"); open(STDERR, ">&OLDERR");
But in these, they are part of a string and the interpreter could not detect by syntactical means that they will be used again. (2) As you're duping, I think you may close the handles explicitly after the restoration of STDOUT and STDERR. close OLDOUT; close OLDERR; In this case, Perl would see a second use of these handles and will not complain. Regards, Adriano Ferreira. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/