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

I am changing the default filehandle using select and I'd like this to be in effect even when I call a subroutine from another module. I've written my own module but it seems that whenI call a subroutine in this module the default filehandle is still STDOUT for the module subroutines.

If there's a way to do what I want please let me know.

THanks.

Replies are listed 'Best First'.
Re: Make select apply to modules as well
by gaal (Parson) on Dec 05, 2004 at 20:32 UTC
    Are you sure? This seems to work for me:
    % perl -le 'select STDERR; f::f(); package f; sub f { print "Now you s +ee me" }' > /dev/null Now you see me % perl -le 'f::f(); package f; sub f { print "Now you don'\''t" }' > / +dev/null (nothing)
      Yeah, it's not working for me. Seems weird.
        Please write a small sample of code that you think should work yet doesn't. If the situation is as you describe, then I'll wind up suggesting that you use the perlbug utility to report a bug in Perl.

        However I strongly suspect that you're missing something, and select works as it is documented. Perhaps select is called again, perhaps the messages you're complaining about come on STDERR thanks to warnings, perhaps a million things.

        But the vanishingly unlikely scenario is that you're encountering a bug in Perl. I don't mean to suggest that you're lying - we've all had the experience of being sure that Perl has a bug because we don't see how what we are seeing is possible otherwise. But, even still, this experience is almost always followed by a, "D'oh!"

        Do these one-liners also not work for you?

        What's the code in the module? Are you certain it isn't doing select somewhere? (Can you post it?)

        What platform are you on?