Summing up here some interesting points brought up in a recent clpmisc thread (link @ GG).

It was noted by "loopology" that a script as simple as

#!/usr/bin/perl use open IN => ":byte"; use constant A => 1; __END__

fails to compile with a Can't locate constant.pm in @INC error.

Then Mumia W. noted that ":byte" is not correct. The correct layer is ":bytes". However, he also claims that "Perl's reaction to the incorrect layer doesn't produce much clarity for the programmer", IMHO rightly so.

Actually the OP had also noted that when using a different layer, e.g. ":encoding(UTF16-BE)" (this is correct) he gets a different error, still having to do with the loading of constant.pm, but also that in both cases the error goes away by switching the order of the use statements. Regarding this, Ben Morrow in a followup to Mumia W's added that in any case it seems that one should not use open before any other module because in no case will applying custom PerlIO layers to the module files produce the correct result. He also suggests that this should probably be documented in open. (Then he suggests a workaround with INIT.)

One final suggestion put forth by Ben Morrow is that the observed behaviour could perhaps be considered a bug in Perl in that require1 probably should not honour the default PerlIO layers set by open, and he considers that this may be fixable or not, depending on backwards compatibility.


1 At least for the require Module form, rather than for the require "file" one.


In reply to Strange behaviour with use open IN => ":byte" by blazar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.