Fmode(3pm)
πΈ Fmode π
okay so bestie, we're talking about the Perl module FileHandle::Fmode (that's the manual name, it lives in the FileHandle::Fmode namespace, and the page itself is filed under Fmode(3pm)) β and it's literally just here to answer one deeply relatable question: is this filehandle reading, writing, or doing both? π
β¨ NAME β¨
FileHandle::Fmode β figure out whether a filehandle is opened for reading, writing, or both. no cap, that's the whole job. π
π SYNOPSIS π
use FileHandle::Fmode qw(:all);
.
.
#$fh and FH are open filehandles
print is_R($fh), "\n";
print is_W(\*FH), "\n";
yes the . lines are just "imagine your code here", it's giving placeholder energy π«Ά
π¦ FUNCTIONS π¦
$bool = is_FH($fh);
$bool = is_FH(\*FH);
- this one is just a more intuitively named alias for
is_arg_ok(). πͺ - returns
1if its argument is an open filehandle. π - returns
0if its argument is something other than an open filehandle. π
$bool = is_arg_ok($fh);
$bool = is_arg_ok(\*FH);
- returns
1if its argument is an open filehandle. π - returns
0if its argument is something other than an open filehandle. π
β οΈ okay so listen: arguments to all the functions below must be open filehandles. if any of those functions get an argument that is not an open filehandle, the function dies with an appropriate error message. literally perishes. π
to make sure your script doesn't suffer such a death, you could first check by passing the argument to is_FH(). or you could wrap the function call in an eval{} block. your call bestie, both work. β¨
π¨ also important: it may be possible that a filehandle opened for writing may become unwritable. if, for example, the disk runs full on Linux, a write attempt will fail, while is_W($fh) still reports true. the behavior for other platforms is not tested. so likeβ¦ don't come for this module when your disk is full, it's doing its best. π
$bool = is_R($fh);
$bool = is_R(\*FH);
- returns true if the filehandle is readable. π
- else returns false. π
$bool = is_W($fh);
$bool = is_W(\*FH);
- returns true if the filehandle is writable. βοΈ
- else returns false. π
$bool = is_RO($fh);
$bool = is_RO(\*FH);
- returns true if the filehandle is readable but not writable. ππ«
- else returns false.
$bool = is_WO($fh);
$bool = is_WO(\*FH);
- returns true if the filehandle is writable but not readable. βοΈπ«
- else returns false.
$bool = is_RW($fh);
$bool = is_RW(\*FH);
- returns true if the filehandle is both readable and writable. π₯ both. versatile icon behavior.
- else returns false.
$bool = is_A($fh);
$bool = is_A(\*FH);
- returns true if the filehandle was opened for appending. π
- else returns false.
- not currently implemented on Win32 with pre-
5.6.1versions of perl β and it dies with an appropriate error message if called on such a platform. π
π CREDITS π
inspired (hmmm β¦ is that the right word ?) by an idea from BrowserUK posted on PerlMonks, in response to a question from dragonchild. the Win32 code (including XS code) was provided by BrowserUK. Zaxo presented the idea of using fcntl() in an earlier PerlMonks thread. π«Ά
thanks to dragonchild and BrowserUK for steering this module in the right direction. π§
thanks to attn.steven.kuo for directing me to the perliol routines that enable us to query filehandles attached to memory objects. π§ β¨
and thanks to Jost Krieger for helping to sort out the test failures that were occurring on Solaris (and some other operating systems too). π
π TODO π
I don't know that anyone still runs pre-5.6.1 perl on Win32 (or anywhere else). however, if someone likes to tell me how is_A() could be made to work on pre-5.6.1 Win32 perl, I would be quite happy to implement it. π so likeβ¦ slide into the inbox if you know something.
π LICENSE π
this program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
copyright 2006-2008, 2009, 2010, 2012, 2024 Sisyphus
π AUTHOR π
Sisyphus <sisyphus at cpan dot org>
and that's the whole page bestie, slay. π
this was perl v5.42.3, dated 2026-08-19, and the manual page itself is Fmode(3pm). go forth and vibe check your filehandles β¨π¦
π¦ where this page comes from
- ubuntu stonking: libfilehandle-fmode-perl 0.15-1build2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms