wfsp has asked for the wisdom of the Perl Monks concerning the following question:

This is based on the example in Programming Perl:
#!/bin/perl5 use strict; use warnings; open ERRORFILE, ">>myprogram.error" or die "Can't open myprogram.error"; open SAVEERR, ">&STDERR"; open STDERR, ">&ERRORFILE"; select STDERR; $| =1; print STDERR "stderr 1\n"; close STDERR; open STDERR, ">&SAVEERR"; print STDERR "stderr 2\n";
I'm getting warnings:
Name "main::SAVEERR" used only once Name "main::ERRORFILE" used only once
Do I need no warnings? If so, where? Apart from that it works as expected.

Thanks in advance
wfsp

Replies are listed 'Best First'.
Re: Warnings while redirecting STDERR
by dpuu (Chaplain) on Aug 27, 2004 at 18:21 UTC
    You just need an extra reference to them. A simple (and good) way would be to localize them:
    local *SAVEERR; local *ERRORFILE;
    --Dave
    Opinions my own; statements of fact may be in error.
      Great stuff! Many thanks, wfsp