Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Warnings while redirecting STDERR

by wfsp (Abbot)
on Aug 27, 2004 at 18:06 UTC ( #386454=perlquestion: print w/replies, xml ) Need Help??

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

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;
    Opinions my own; statements of fact may be in error.
      Great stuff! Many thanks, wfsp

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://386454]
Approved by ybiC
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2023-12-09 12:49 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (38 votes). Check out past polls.