blazar has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|