Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: Track open file handles

by shmem (Chancellor)
on Apr 06, 2017 at 08:52 UTC ( [id://1187229]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Track open file handles
in thread Track open file handles

Without Hash::Util::FieldHash, no reference to the filehandle is kept anywhere (since the hash would only keep a stringified version)

But this stringified key / value pair would not be destroyed if its object goes out of scope. It is just that what Hash::Util::FieldHash does for me - the housekeeping. Why shouldn't I use it?

I think returning the filehandle is a good idea ... Maybe you can keep a weakened reference to the handle though

Again, that is what Hash::Util::FieldHash does for me. It keeps a weakened reference and uses the decimal value of the adress part (0xdeadbeef) as key into the fieldhash. The weakened reference has magic attached which provides for deletion of the hash entry when it's freed.

But! returning a weakened reference from get_fds is a good idea. Thank you.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^5: Track open file handles
by Eily (Monsignor) on Apr 06, 2017 at 09:15 UTC
    Why shouldn't I use it?

    You should, I misread your answer actually (I thought you said the hash would prevent the deletion of the handles), I agree with you that this feature is useful.

    But! returning a weakened reference from get_fds is a good idea. Thank you.

    Adding it at the last moment, or storing it as a member as soon as the handle is opened (even if that means having two weak reference to the same handle in nearly the same place) is pretty much the same thing. There's a difference when you return $fd => { fd => $fd, %{$fd{$_}} } rather than id_2obj($_) => $fd{$_} though, in the first case, if the user keeps the hashref, it will always have the values it had when acquired, while in the latter, the "close" and "closetime" value will appear when the handle is closed. I like the first version better, because you have to call get_fds to get up-to-date information.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1187229]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-03-28 10:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found