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

I'm using a sub which expects as parameter a string describing a layer, such as ':crlf' etc., which it then passes on to open(). My question: What do I have to specify if I don't want to have any particular layer, but just the default behaviour? Is it sufficient to just use the empty string, ''?

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re: How to specify the default IO layer?
by ikegami (Patriarch) on May 26, 2009 at 13:18 UTC

    I'm using a sub which expects as parameter a string describing a layer. [...] Is it sufficient to just use the empty string, ''

    It doesn't matter what you pass to your sub. What matters is what you pass to open. Passing an empty string to open (for the second argument) is an error. You also need to specify the mode.

    >perl -e"open my $fh, '', 'foo'" Unknown open() mode '' at -e line 1.

    Not specifying any layers causes open to use the default (hardcoded, from $ENV{PERLIO} or from use open).

    sub myopen { my (..., $perlio, ...) = @_; $perlio ||= ''; ... open(my $fh, ">$perlio", ...) or die ...; ... } myopen(..., ':raw:perlio', ...); # bin mode with buffering myopen(..., '', ...); # default myopen(..., ); # default
Re: How to specify the default IO layer?
by Tux (Canon) on May 26, 2009 at 13:23 UTC

    You can set the default IO layer in $ENV{PERLIO} if you have a perl with perlio.

    $ perl -wle'print"\x{20ac}"' Wide character in print at -e line 1. € $ env PERLIO=:utf8 perl -wle'print"\x{20ac}"' € $

    Enjoy, Have FUN! H.Merijn
Re: How to specify the default IO layer?
by Anonymous Monk on May 26, 2009 at 13:45 UTC
    see open pragma
    { #default myfoo(...); } { #override use open ':encoding(UTF-8)'; myfoo(...); }
Re: How to specify the default IO layer?
by rovf (Priest) on May 27, 2009 at 13:50 UTC

    Thanks for clarification. I fixed the function which actually calls the open, so that passing a layer is now optional.

    -- 
    Ronald Fischer <ynnor@mm.st>