in reply to How do I tell if a handle is open for writing?
sub is_writable_fh { my($fh)=@_; local $\=''; return print $fh ''; } open(F1,"< $0") or die "Couldn't open '$0' for read: $!\n"; print "F1 is".(is_writable_fh(\*F1)?"":"n't")." writable.\n"; open(F2,">> $0") or die "Couldn't open '$0' for append: $!\n"; print "F2 is".(is_writable_fh(\*F2)?"":"n't")." writable.\n";
Zaxo's solution will tell you whether you have write permissions to the file, but not whether you have write permissions to the filehandle.
|
|---|
| 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:44 UTC | |
by Anonymous Monk on Mar 01, 2006 at 17:02 UTC |