FileHandle appears to inherit from IO::File, which inherits from IO::Handle. In the docs for IO::Handle, there is this comment:
# # 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. # sub DESTROY {}
So when the object goes out of scope and is destroyed, those FileHandle objects will be destroyed as well, closing the files. So the scope of the open files won't be longer than the scope of the object.
I think the underlying question is the classic one of concurrency -- what if multiple processes are reading/write the same file. Keeping a file open for a limited scope minimizes chances of conflict, but doesn't eliminate them. There still needs to be thought given to file locking, file pointers, buffering, etc.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
In reply to Re: FileHandle objects as data members of another object
by xdg
in thread FileHandle objects as data members of another object
by jkeenan1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |