The following code will give you the mode that a given handle is opened in (<
, >
, etc.):
use Fcntl qw(F_GETFL);
my $flags = fcntl($fh, F_GETFL, my $junk);
$flags
is a number indicating the open mode (numbers defined by other macros provided by Fcntl). This, however, does not work on a Strawberry Perl installation. It fails with the following message:
Your vendor has not defined Fcntl macro F_GETFL
How can this be achieved on a Windows installation of Perl?
The context is that I'm investigating a fix for Data::Transform::ExplicitMetadata. Its purpose is to make Perl structures serializable via JSON, and one thing that it needs to serialize is open file handles. See the current code here.