in reply to Re^2: diagnostics, STDERR, and codepage conversions
in thread diagnostics, STDERR, and codepage conversions

open gives examples of how to save, redirect, and restore file handles. That example does not do things the way you did. Yes, doing it the wrong way is why your code isn't redirecting correctly. Yes, that was the question you asked that I was addressing. No, I had no comment on your second question.

The open examples (implicitly) pass typeglobs as arguments to open(). They don't use any typeglob syntax, not a single use of * except in some example regular expressions). They don't manipulate typeglobs directly in hopes of having a similar impact on the file handles contained in them.

Rephrased more clearly and more correctly: Don't copy, save, or restore typeglobs that contain open file handles.

And, of course, when the standard documentation shows how to do something, it is often a good idea to pay attention.

I am not introducing new typeglobs (other than a localised version of STDERR)

Yep, you even figured out which one I'm talking about, but refused to belive it? :)

If it was a good idea to save/restore a file handle with a simple local(*STDERR), do you think the example of how to save/restore a file handle in the standard open docs would have avoided such?

- tye        

Replies are listed 'Best First'.
Re^4: diagnostics, STDERR, and codepage conversions (open)
by Tanktalus (Canon) on Aug 13, 2007 at 22:49 UTC

    Ok, much more clear now, thanks. Just FYI - the reason why I didn't believe it is because I learned that idiom here ;-) e.g., an article by our own merlyn. Ok, that's not specifically here... but it's a site I only learned about from perlmonks. And the author is rumoured to be reasonably proficient... :-> (Ok, appeal to authority - he could be wrong about some stuff, even in his specialty.) Then, [id://3989;BIT=local *STDERR;BIS=%3B] shows ikegami using it without comment on style (perhaps you just missed them at the time). So I plead educated ignorance - the masters were doing it, so I thought it was a good idea ;-)

    Just to continue with the thread drift (though I still would like someone to answer the original questions if they have any help), I'm wondering why they suck. As in, what way? Is it an accidental feature that could be removed from 5.10 or something?

    And I found (remembered) another way to kill the messages without redirecting, which is better since it will be much more specific: set the __WARN__ handler to ignore the warning, and that will keep the diagnostics from being hit (since it's a __WARN__ handler, too):

    my $oldwarn = $SIG{__WARN__}; local $SIG{__WARN__} = sub { my ($msg) = @_; if ($msg =~ /utf8_heavy/) { # do nothing } elsif ($oldwarn) { goto &$oldwarn if $oldwarn; } else { warn @_; } };
    And now I don't need to redirect, but I'm still interested in it.