http://www.perlmonks.org?node_id=506419


in reply to How do I tell if a handle is open for writing?

Well I may be a member of the idiots' club along with you, and this certainly isn't pretty, but is there a reason this wouldn't work?:
eval { my $pos = $fh->tell; $fh->print('1'); $fh->seek($pos); }; my $ready_for_writing = ($@) ? 0 : 1;
update please ignore this and listen to Zaxo :-)

Replies are listed 'Best First'.
Re^2: How do I tell if a handle is open for writing?
by Aristotle (Chancellor) on Nov 07, 2005 at 16:44 UTC

    You mean other than that it clobbers some content in the file? :-)

    Makeshifts last the longest.

      If this was worth salvaging, I could add in a seek() before the original tell to avoid that problem. But since it's crap anyway, I won't bother :-).
Re^2: How do I tell if a handle is open for writing?
by VSarkiss (Monsignor) on Nov 07, 2005 at 16:51 UTC
      I did that once. I wouldn't recommend it to anyone -- it tends to make your mother a little crazy...

      --DrWhy

      "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."