1Fmode(3) User Contributed Perl Documentation Fmode(3)
2
3
4
6 FileHandle::Fmode - determine whether a filehandle is opened for read‐
7 ing, writing, or both.
8
10 use FileHandle::Fmode qw(:all);
11 .
12 .
13 #$fh and FH are open filehandles
14 print is_R($fh), "\n";
15 print is_W(\*FH), "\n";
16
18 $bool = is_arg_ok($fh);
19 $bool = is_arg_ok(\*FH);
20 Returns 1 if its argument is an open filehandle.
21 Returns 0 if its argument is something other than an open filehandle.
22
23 Arguments to the following functions must be open filehandles. If
24 any of those functions receive an argument that is not an open
25 filehandle then the function dies with an appropriate error message.
26 To ensure that your script won't suffer such a death, you could first
27 check by passing the argument to is_arg_ok(). Or you could wrap the
28 function call in an eval{} block.
29
30 $bool = is_R($fh);
31 $bool = is_R(\*FH);
32 Returns true if the filehandle is readable.
33 Else returns false.
34
35 $bool = is_W($fh);
36 $bool = is_W(\*FH);
37 Returns true if the filehandle is writable.
38 Else returns false
39
40 $bool = is_RO($fh);
41 $bool = is_RO(\*FH);
42 Returns true if the filehandle is readable but not writable.
43 Else returns false
44
45 $bool = is_WO($fh);
46 $bool = is_WO(\*FH);
47 Returns true if the filehandle is writable but not readable.
48 Else returns false
49
50 $bool = is_RW($fh);
51 $bool = is_RW(\*FH);
52 Returns true if the filehandle is both readable and writable.
53 Else returns false
54
55 $bool = is_A($fh);
56 $bool = is_A(\*FH);
57
58 Returns true if the filehandle was opened for appending.
59 Else returns false.
60 Not currently implemented on Win32 with pre-5.6.1 versions of perl (and
61 dies with appropriate error message if called on such a platform).
62
64 Inspired (hmmm ... is that the right word ?) by an idea from BrowserUK
65 posted on PerlMonks in response to a question from dragonchild. Win32
66 code (including XS code) provided by BrowserUK. Zaxo presented the idea
67 of using fcntl() in an earlier PerlMonks thread.
68
69 Thanks to dragonchild and BrowserUK for steering this module in
70 the right direction.
71
72 Thanks to attn.steven.kuo for directing me to the perliol routines
73 that enable us to query filehandles attached to memory objects.
74
75 And thanks to Jost Krieger for helping to sort out the test failures that
76 were occurring on Solaris (and some other operating systems too).
77
79 I don't know that anyone still runs pre-5.6.1 perl on Win32. However, if
80 someone likes to tell me how is_A() could be made to work on pre-5.6.1
81 Win32 perl, I would be quite happy to implement it.
82
84 This program is free software; you may redistribute it and/or
85 modify it under the same terms as Perl itself.
86
88 Sisyphus <kalinabears at iinet dot net dot au>
89
90
91
92perl v5.8.8 2006-05-12 Fmode(3)