Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > destroying IO::Handle without close()ing the file

Reply
Thread Tools

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

 
 
Ilya Zakharevich
Guest
Posts: n/a
 
      10-06-2010
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.
 
Reply With Quote
 
 
 
 
Ilya Zakharevich
Guest
Posts: n/a
 
      10-07-2010
On 2010-10-06, Ben Morrow <(E-Mail Removed)> wrote:
>> So how do people destroy the handle without close()ing?


> Looking at Perl_io_close in doio.c suggests using
>
> binmode $FH, "op" 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
read one line of input from file and then destroying it! waffle.horn@googlemail.com C Programming 11 04-05-2007 01:37 AM
read one line of input from file and then destroying it! waffle.horn@googlemail.com C Programming 0 04-04-2007 11:45 AM
read one line of input from file and then destroying it! waffle.horn@googlemail.com C Programming 0 04-04-2007 11:45 AM
How can I put 2 img atop of eachother in a table without destroying the layout? WalterTemp HTML 1 08-18-2006 08:45 PM
How to walk through a Stack without destroying it? Andrew C++ 2 08-01-2004 05:32 PM



Advertisments