How to redirect my $fh to STDOUT?

Discussion in 'Perl Misc' started by bill, Dec 23, 2004.

  1. bill

    bill Guest

    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
    bill, Dec 23, 2004
    #1
    1. Advertising

  2. bill <> wrote in news:cqd9e0$3i4$1
    @reader1.panix.com:

    > 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";


    --
    A. Sinan Unur
    d
    (remove '.invalid' and reverse each component for email address)
    A. Sinan Unur, Dec 23, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VisionSet
    Replies:
    6
    Views:
    9,611
    Sudsy
    Sep 20, 2003
  2. Elad
    Replies:
    0
    Views:
    397
  3. Sal
    Replies:
    1
    Views:
    372
  4. Andreas S
    Replies:
    3
    Views:
    243
    Eric Hodel
    Dec 9, 2006
  5. Replies:
    2
    Views:
    319
    A. Sinan Unur
    Dec 7, 2005
Loading...

Share This Page