3

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.

Nate Glenn
  • 6,455
  • 8
  • 52
  • 95
  • Perhaps to step back and look *why* you need $flags, so answer might be in other direction. – mpapec Oct 14 '14 at 11:53
  • Are you asking about the Perl handle or the underlying system handle? – ikegami Oct 14 '14 at 12:13
  • @mpapec I added the context to the question. – Nate Glenn Oct 14 '14 at 12:28
  • @ikegami I'm not really sure. See my edit for the context. I'd like to be able to tell if a file was opened with '<', '>', '<<', etc. – Nate Glenn Oct 14 '14 at 12:29
  • I take that to mean "anything I can grab since the feature is going to be insanely fragile no matter what I do". As such, you could grab the mode Perl has for it. You can see it in `perl -MDevel::Peek -e'Dump *STDOUT{IO}'`. You should be able to grab it using B::. – ikegami Oct 14 '14 at 14:07
  • (I suggest you do like Storable and leave globs and file handles unsupported. It simply makes no sense. They're not data, so they can't be meaningfully serialized.) – ikegami Oct 14 '14 at 14:07
  • @ikegami Thanks, I'll look into. It's not my module, and the module specifically claims support for stuff that's not normally serializable, so I don't want to submit an issue saying to remove functionality. I just want this fixed because it's a dependency for Devel::hdb, which I happen to love. – Nate Glenn Oct 14 '14 at 14:16
  • @ikegami: almost had it: https://rt.perl.org/Ticket/Display.html?id=122975&results=d4384595fd8d2232b24500da4c3ac8d2 – Nate Glenn Oct 14 '14 at 15:22

0 Answers0