On 22/08/19 2:20 AM, Warren Young wrote:
On Aug 21, 2019, at 7:35 AM, Xinhuan Zheng <xzheng@xxxxxxxxxxxxxxxxx> wrote:
my $s = IO::Select->new( $fh );
if ( $io->can_write( 10 ) {
That’s not designed to do what you hope. select(2) is a system call intended for use on network socket handles, not file handles. Since socket handles and file handles are compatible on a Unix type system (including CentOS) the call doesn’t fail, but it *cannot* report the information you’re hoping to get.
I would first try calling the -w operator:
print_to_file() if -w $fh;
First off I would be remiss if I didn't point out that CentOS 5 has been
EOL for years, that said...
You're dealing with perl here and so this might be better off asking in
a perl list. The -X system of tests as documented with "perldoc -f -X"
do not by default test actual ability to read and write files, but
instead just check the file mode bits as returned by stat(), thus the -w
test will not reflect the filesystem being in read-only mode.
There are two ways to get around this. One is to to use the filetest
pragma which changes the behavior of the -X tests to use the access(2)
system function:
{ use filetest 'access';
print_to_file() if -w $fh;
}
The other way is to use POSIX::access() directly (this requires the file
name or path):
use POSIX qw(access W_OK);
...
print_to_file() if access($filepath, W_OK);
Note that there are caveats to either of the above approaches as per
documentation. See the following for additional info:
perldoc -f -X
perldoc filetest
access(2)
Peter
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
https://lists.centos.org/mailman/listinfo/centos