leriksen has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to work out how to get a file handle object from IO::File to be opened with specific PerlIO layers, and also specify the opening permissions with POSIX flags.
An example WITHOUT using POSIX flags is
#!/usr/bin/perl -w use strict; use IO::File; use PerlIO; use Data::Dumper; my $fname = 'big.txt'; my $fh = IO::File->new($fname, "<:utf8") or die "cannot open $fname :: $!"; STDERR->print(Dumper([PerlIO::get_layers($fh)])); $fh->close();

Output from this is
$VAR1 = [ 'unix', 'perlio', 'utf8' ];

I want to do something like this
#!/usr/bin/perl -w use strict; use IO::File; use PerlIO; use Data::Dumper; my $fname = 'big.txt'; my $fh = IO::File->new($fname, O_RDONLY, ":utf8") or die "cannot open $fname :: $!"; STDERR->print(Dumper([PerlIO::get_layers($fh)])); $fh->close();

and get the same result, but I can't seem to get the syntax right - any clues of how to use POSIX flags and PerlIO layers together ??

+++++++++++++++++
#!/usr/bin/perl
use warnings;use strict;use brain;

Replies are listed 'Best First'.
Re: Getting IO::File, PerlIO Layers and POSIX to play together
by gellyfish (Monsignor) on Jul 07, 2004 at 12:08 UTC

    In short you can't do this - if you are supplying POSIX mode and permissions flags then IO::File::open() will use sysopen() which does not know about IO layers.

    /J\

      I'm not sure but isn't it possible to binmode the file hadle with the given IO layer after the sysopen?