On Mon, 07 Aug 2000 17:43:29 -0700, Nathan Wiger wrote:
>> I'd rather have a filehandle stringify to
>> the filename instead.
>
>Great minds think alike. :-) I was actually going to add this to the new
>version of the open() RFC as a possible use of RFC 49's
>soon-to-be-renamed STRING method.
>
>Now I know I have at least I have one supporter! ;-)
This question has been asked a few times on comp.lang.perl.misc. It is
in general not possible. On Unix, a file can have more than one name.
The name can be changed while the file is open. Do you want the
filehandle to track that? Another file could have taken the name, after
the first file was opened. It's even possible that the name is deleted,
so there IS no more name for it.
Now, what you can do, is stat() on the filehandle, and pick out the
device ID and the inode number. That combination is unique for each
file.
But, the whole world is not Unix. If you want something to be a part of
Perl's core, it should be portable as well.
--
Bart.