in reply to How do I tell if a handle is open for writing?
stat or, more conveniently, the -w file test operator. Both work fine on open handles, though we're mostly used to feeding them file names.
Update: Oops, got the wrong end of the stick. Here's how to check the open flags to see if the handle is currently writable:
use Fcntl; sub writable { my $fh = shift; (O_WRONLY | O_RDWR) & fcntl( $fh, F_GETFL, my $slush); } for (qw/ > < >> +< +> /) { open my $fh, $_, 'foo' or warn $! and next; print "$_\t", writable($fh)? 'writable.': 'not writable.', $/; } __END__ > writable. < not writable. >> writable. +< writable. +> writable.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I tell if a handle is open for writing?
by DrWhy (Chaplain) on Nov 07, 2005 at 17:16 UTC | |
by Zaxo (Archbishop) on Nov 07, 2005 at 19:06 UTC | |
by DrWhy (Chaplain) on Nov 08, 2005 at 14:17 UTC | |
|
Re^2: How do I tell if a handle is open for writing?
by sauoq (Abbot) on Nov 07, 2005 at 17:11 UTC | |
|
Re^2: How do I tell if a handle is open for writing?
by dragonchild (Archbishop) on Feb 28, 2006 at 18:38 UTC |