dragonchild has asked for the wisdom of the Perl Monks concerning the following question:
In DBM::Deep 0.98 and above, we added the feature that you could pass in your own filehandle instead of a filename. (This allows you to use the *DATA filehandle as a DBM::Deep file.) The only issue is that DBM::Deep opens its filehandles as read-write handles. Potentially, you could pass us a read-only filehandle. (I'm not even going to comment on the stupidity of passing a write-only filehandle to DBM::Deep.)
If you do, then accidentally try to modify the data, then a warning gets popped up in print() saying "Cannot print to a closed filehandle". Fatal doesn't work because print() cannot be overridden. While I could trap the warning, I'd still prefer to detect the fact that the filehandle isn't writable and throw an error.
I found the following code somewhere on Perlmonks (Thanks, Zaxo!) and it does the trick:
The code works great . . . on systems whose Fcntl have defined F_GETFL. Unfortunately, that doesn't seem to include Win32 (at least not for ActiveState 5.8.6).sub _is_writable { my $fh = shift; (O_WRONLY | O_RDWR) & fcntl( $fh, F_GETFL, my $slush = 0); }
Other than disabling that function for Win32, how should I go about fixing this problem?
Update: Zaxo's code is found here
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: F_GETFL and Win32
by PodMaster (Abbot) on Mar 08, 2006 at 04:40 UTC | |
|
Re: F_GETFL and Win32
by BrowserUk (Patriarch) on Mar 08, 2006 at 04:56 UTC | |
by syphilis (Archbishop) on Mar 08, 2006 at 22:23 UTC | |
by BrowserUk (Patriarch) on Mar 08, 2006 at 22:58 UTC | |
by syphilis (Archbishop) on Mar 09, 2006 at 01:08 UTC |