in reply to Re^7: Best way to check if something is a file handle?
in thread Best way to check if something is a file handle?
That is a check for file existence, not a check as to whether you've been passed something intended to be treated as a filename. A filename may be the name of a file that does not (yet) exist.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Best way to check if something is a file handle?
by BrowserUk (Patriarch) on Jul 12, 2012 at 06:00 UTC | |
A filename may be the name of a file that does not (yet) exist. I've been sitting on this reply for a day or so trying to decide if it contributes anything. I can't make up my mind, so I'll let you dismiss it or not. If the sole purpose of the module is to determine if a passed parameter is an IO handle, then why does it have is_filename()? Surely all that is needed, at most is:
And what does is_filename() mean when it reports true? For example, will it consider fred"bill"smith as valid? Which it possibly is on *nix, but not on NTFS. Now with respect to making the required determination of whether the passed parameter represents a "legitimate" IO target, you dismissed my earlier suggestion of using fileno because it didn't work for ram files (IO::Scalar & open $fh, '>', \$ramfile) , (and IO:All object, but I'll get back to that!). Running it against a simplified version of your test suite confirms that is the only failure: <Reveal this spoiler or all in this thread>
I was aware of this, but I also contend that it is a bug in the implementation of ramfiles. Why should I not be able to duplicate a ramfile handle using open $dup, '&=', fileno( $ramfh ) ... as I can with any other filehandle? And I suspect that limitation -- the failure of an IO object to respond to fileno in an appropriate and consistent way -- is the cause of the IO::All object failure also. Whilst I believe that to be a bug that needs fixing, it is a legitimate position to take to say that your module -- with its mechanism that detects a ramfile handle (and I assume an IO::All object) as a suitable target for many IO operations -- fulfills a useful function, now, that is otherwise not easily available unless and until those IO-like thingies do respond to fileno correctly. When this thread came up, I knew that I had solved this problem (for ramfiles) sometime in the past. I did do a search of my system and PM, but failed to find the code. This morning I got around to checking my backups from my previous system and found it. This is how I did it:
I haven't tested it against IO:All as I don't use it, but maybe there is something there that is useful to you. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |