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

Reply via email to