S
Sisyphus
Hi,
On unix, with filehandles connected to normal files, we can query the
read/write status of the filehandle by examining the return value of the
fcntl() function:
use Fcntl;
# some code that creates the open $filehandle.
my $fmode = fcntl($filehandle, F_GETFL, my $slush = 0);
The value of $fmode will allow us to determine whether the filehandle is
readonly, writeonly, or readable/writable.
But with perl 5.8, it's possible to create filehandles connected to memory
objects:
use warnings;
use strict;
my ($fh1, $fh2, $var1, $var2);
open $fh1, '>', \$var1 or die $!;
print $fh1 "hello"; # $var1 contains "hello"
open $fh2, '<', \$var1 or die $!;
$var2 = <$fh2>; # $var2 contains "hello";
close $fh1 or die $!;
close $fh2 or die $!;
print $var1, " ", $var2, "\n"; # prints "hello hello"
__END__
But now the fcntl() function is unable to provide information that I can use
to determine the read/write status of $fh1and $fh2.
For both $fh1 and $fh2 the fcntl() function will return undef - and fileno()
will return -1.
The question:
How can I determine the read/write status of an open filehandle that's
connected to a memory object ?
Cheers,
Rob
On unix, with filehandles connected to normal files, we can query the
read/write status of the filehandle by examining the return value of the
fcntl() function:
use Fcntl;
# some code that creates the open $filehandle.
my $fmode = fcntl($filehandle, F_GETFL, my $slush = 0);
The value of $fmode will allow us to determine whether the filehandle is
readonly, writeonly, or readable/writable.
But with perl 5.8, it's possible to create filehandles connected to memory
objects:
use warnings;
use strict;
my ($fh1, $fh2, $var1, $var2);
open $fh1, '>', \$var1 or die $!;
print $fh1 "hello"; # $var1 contains "hello"
open $fh2, '<', \$var1 or die $!;
$var2 = <$fh2>; # $var2 contains "hello";
close $fh1 or die $!;
close $fh2 or die $!;
print $var1, " ", $var2, "\n"; # prints "hello hello"
__END__
But now the fcntl() function is unable to provide information that I can use
to determine the read/write status of $fh1and $fh2.
For both $fh1 and $fh2 the fcntl() function will return undef - and fileno()
will return -1.
The question:
How can I determine the read/write status of an open filehandle that's
connected to a memory object ?
Cheers,
Rob