Not long ago I uploaded FileHandle::Fmode to CPAN. I'm not actually sure that it has been used much (if at all) but you might find it useful.

It doesn't distinguish between "write mode" and "append mode" (which, when I read your post more closely, is what you've posted about). Ottomh, I don't know how you can distinguish between a "clobbered/writable" filehandle and an "unclobbered/appendable" filehandle with pre-5.6 perl. But with perl 5.6 and later the distinction can be readily facilitated and I'll post a new version of FileHandle::Fmode that makes that distinction (for perl 5.6 and later only)tonight. In the meantime, if you have Inline::C, you might be able to make use of the following code (which is probably a little light-on wrt error checking).
use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; SV * my_fmode(SV * handle) { int x; IO *io; io = sv_2io(handle); x = IoTYPE(io); if (x == IoTYPE_RDONLY) return newSVuv(1); if (x == IoTYPE_WRONLY) return newSVuv(2); if (x == IoTYPE_RDWR) return newSVuv(3); if (x == IoTYPE_APPEND) return newSVuv(4); warn("Unable to determine mode\n"); return 0; } EOC open($fh1, '>', 'test1.txt') or die "Can't open \$fh1: $!"; open($fh2, '>>', 'test2.txt') or die "Can't open \$fh2: $!"; print my_fmode($fh1), " ", my_fmode($fh2), "\n"; close($fh1) or die "Can't close \$fh1: $!"; close($fh2) or die "Can't close \$fh2: $!";


Cheers,
Rob

In reply to Re: How do i determine which mode the file has open ? (write or append mode) by syphilis
in thread How do i determine which mode the file has open ? (write or append mode) by loga

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.