Re: RFC 30 (v2) STDIN, STDOUT, and STDERR should be renamed
[email protected] (Nick Ing-Simmons) Wed, 16 Aug 2000 20:37:02 +0000
| Newsgroups | perl.perl6.language.io |
|---|---|
| Message-ID | <E13P9vq-00033S-00@roam1> |
Nathan Wiger <[email protected]> writes: > >For other stuff, like print(), instead of using the "currently selected >filehandle", just always have it print to $STDOUT unless something's >specified. So: > > $oldstdout = $STDOUT; > $STDOUT = $myfileobject; > print "Hello, world!"; # always prints to $STDOUT, which in > # this case is a copy of $myfileobject > > $STDOUT = $oldstdout; > print "Hello, world again!"; Translate this please: #!perl -x sub show_things { my $arg = shift; print Dumper($arg); print STDOUT "Dumped ",ref($arg),"\n"; } select(STDERR); show_things({a => 1}); open(my $foo,">dump"); select($foo); show_things({b => 2}); close($foo); select(STDOUT); show_things({c => 3}); __END__ This technique is extremely handy! Now if only one could divert warn/die messages to STDERR by a similar trick -- Nick Ing-Simmons