destroying IO::Handle without close()ing the file

Discussion in 'Perl Misc' started by Ilya Zakharevich, Oct 6, 2010.

  1. The comment in IO/Handle.pm says:

    # There is no need for DESTROY to do anything, because when the
    # last reference to an IO object is gone, Perl automatically
    # closes its associated files (if any). However, to avoid any
    # attempts to autoload DESTROY, we here define it to do nothing.

    So how do people destroy the handle without close()ing? I think some
    POSIX magic should be done, but which one?

    Puzzled,
    Ilya

    P.S. WHY?

    Suppose I make a same-fd duplicate (open "<&=11"). Now I want
    to get rid of it - but I must not close() the original handle -
    hence not close() the duplicate IO::Handle.
    Ilya Zakharevich, Oct 6, 2010
    #1
    1. Advertising

  2. On 2010-10-06, Ben Morrow <> wrote:
    >> So how do people destroy the handle without close()ing?


    > Looking at Perl_io_close in doio.c suggests using
    >
    > binmode $FH, ":pop" while PerlIO::get_layers $FH;
    >
    > before the handle goes out of scope. After this fileno $FH returns -1,
    > and ktrace confirms that closing it doesn't attempt to call close(2).


    Thanks for a wonderful piece of voodoo!
    Ilya
    Ilya Zakharevich, Oct 7, 2010
    #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. Dietrich
    Replies:
    1
    Views:
    619
    Joe Smith
    Jul 22, 2004
  2. Andrew
    Replies:
    2
    Views:
    411
    Jonathan Turkanis
    Aug 1, 2004
  3. WalterTemp
    Replies:
    1
    Views:
    284
    Neredbojias
    Aug 18, 2006
  4. Iñaki Baz Castillo
    Replies:
    7
    Views:
    807
    Iñaki Baz Castillo
    Jan 12, 2010
  5. Walter Beierdonck

    Self.close() window without the dialog close?Yes/NO

    Walter Beierdonck, Apr 29, 2004, in forum: Javascript
    Replies:
    1
    Views:
    326
    Grant Wagner
    Apr 30, 2004
Loading...

Share This Page