How to redirect my $fh to STDOUT?

B

bill

I'm debugging a script not written by me, and having a rough time
of it (it is a huge script with no subroutines; uses no modules;
etc.). Near the top of the file (i.e. near the beginning of this
script's execution), a lexical filehandle is opened for writing,
and remains open throughout. It would be useful if I could redirect
this lexical filehandle to STDOUT. I've read the docs on "duplicating"
filehandles, but I confess that I don't quite understand them.
Could someone show me how I'd redirect an open lexical write handle
from a file to STDOUT?

Thanks!

bill
 
A

A. Sinan Unur

I'm debugging a script not written by me, and having a rough time
of it (it is a huge script with no subroutines; uses no modules;
etc.).

Good luck.
Near the top of the file (i.e. near the beginning of this
script's execution), a lexical filehandle is opened for writing,
and remains open throughout. It would be useful if I could redirect
this lexical filehandle to STDOUT.

Would the following do what you want?

#! perl

use strict;
use warnings;

# open my $fh, '>', 'somefile' or die $!;
my $fh = \*STDOUT;

print $fh "This should print to STDOUT\n";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,268
Messages
2,571,096
Members
48,773
Latest member
Kaybee

Latest Threads

Top