in reply to Test for writable filehandles on win32
Given that the bug report suggests only the is_W() function is used from FileHandle::Fmode I don't see why you can't replace the entire dependency with this short sub:
sub is_W { my $fh = shift; return 0 unless defined $fh; return 0 unless defined fileno $fh; local $\ = ''; # just in case no warnings; # temporarily disable warnings #my ($atime,$mtime) = (stat($fh))[8,9]; my $is_w = print $fh ''; #eval{ utime $atime, $mtime, $fh }; # can fail if futimes not avai +lable return $is_w; } my $file = "C:/tmp.txt"; printf "Null fh %d\n", is_W(); open F, ">", $file or die "Can't create $file $!\n"; printf "Writable fh %d\n", is_W(*F); close F; open F, $file or die "Can't create $file $!\n"; printf "Readable fh %d\n", is_W(*F); close F; printf "STDIN %d\n", is_W(*STDIN); printf "STDOUT %d\n", is_W(*STDOUT); printf "STDERR %d\n", is_W(*STDERR); __DATA__ Null fh 0 Writable fh 1 Readable fh 0 STDIN 0 STDOUT 1 STDERR 1
Update added "no warnings;" as per barts suggestion. Added comments containing mtime restoration code (if desired) also per bart.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Test for writable filehandles on win32
by dragonchild (Archbishop) on Jun 09, 2008 at 18:36 UTC | |
by bart (Canon) on Jun 09, 2008 at 19:32 UTC | |
by tachyon-II (Chaplain) on Jun 09, 2008 at 20:25 UTC | |
by dragonchild (Archbishop) on Jun 09, 2008 at 20:40 UTC | |
|
Re^2: Test for writable filehandles on win32
by bart (Canon) on Jun 09, 2008 at 19:38 UTC |