strange behaviour with 'use open IN => ":byte"

Discussion in 'Perl Misc' started by loopology, Sep 15, 2007.

  1. loopology

    loopology Guest

    If I run this script:

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

    on a MacBook Pro (Intel)

    With perl version 5.8.6 (the pre-installed)

    I get this error:
    Can't locate constant.pm in @INC (@INC contains: /sw/lib/perl5 /sw/lib/
    perl5/dar
    win /System/Library/Perl/5.8.6/darwin-thread-multi-2level /System/
    Library/Perl/5
    ..8.6 /Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/
    5.8.6 /Library
    /Perl /Network/Library/Perl/5.8.6/darwin-thread-multi-2level /Network/
    Library/Pe
    rl/5.8.6 /Network/Library/Perl /System/Library/Perl/Extras/5.8.6/
    darwin-thread-m
    ulti-2level /System/Library/Perl/Extras/5.8.6 /Library/Perl/5.8.1 .)
    at ./tst.pl
    line 3.

    if I change the line to:
    use open IN => ":encoding(UTF16-BE)";
    I get this error:
    Unrecognized character \xE0 at /System/Library/Perl/5.8.6/constant.pm
    line 1.

    In both cases:
    If I swap the lines, everything runs smoothly.

    Anyone seen this behaviour?
    What to do about it?

    Thanks
    Bernhard

    Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
    Platform:
    osname=darwin, osvers=8.0, archname=darwin-thread-multi-2level
    uname='darwin b19.apple.com 8.0 darwin kernel version 8.3.0: mon
    oct 3 20:04
    :04 pdt 2005; root:xnu-792.6.22.obj~2release_ppc power macintosh
    powerpc '
    config_args='-ds -e -Dprefix=/usr -Dccflags=-g -pipe -Dldflags=-
    Dman3ext=3
    pm -Duseithreads -Duseshrplib'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define
    usemultiplicity=de
    fine
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    Compiler:
    cc='cc', ccflags ='-g -pipe -fno-common -DPERL_DARWIN -no-cpp-
    precomp -fno-s
    trict-aliasing -I/usr/local/include',
    optimize='-O3',
    cppflags='-no-cpp-precomp -g -pipe -fno-common -DPERL_DARWIN -no-
    cpp-precomp
    -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='4.0.1 (Apple Computer, Inc. build
    5363)', gccosand
    vers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define,
    longdblsize=16

    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
    lseeksize
    =8
    alignbytes=8, prototype=define
    Linker and Libraries:
    ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags ='-L/usr/local/
    lib'
    libpth=/usr/local/lib /usr/lib
    libs=-ldbm -ldl -lm -lc
    perllibs=-ldl -lm -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=true,
    libperl=libperl.dylib
    gnulibc_version=''
    Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-bundle -undefined dynamic_lookup -L/
    usr/local/li
    b'


    Characteristics of this binary (from libperl):
    Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
    PERL_IMPLICIT_
    CONTEXT
    Locally applied patches:
    23953 - fix for File::path::rmtree CAN-2004-0452 security
    issue
    33990 - fix for setuid perl security issues
    SPRINTF0 - fixes for sprintf formatting issues - CVE-2005-3962
    Built under darwin
    Compiled at Nov 1 2006 17:07:31
    %ENV:
    PERL5LIB="/sw/lib/perl5:/sw/lib/perl5/darwin"
    @INC:
    /sw/lib/perl5
    /sw/lib/perl5/darwin
    /System/Library/Perl/5.8.6/darwin-thread-multi-2level
    /System/Library/Perl/5.8.6
    /Library/Perl/5.8.6/darwin-thread-multi-2level
    /Library/Perl/5.8.6
    /Library/Perl
    /Network/Library/Perl/5.8.6/darwin-thread-multi-2level
    /Network/Library/Perl/5.8.6
    /Network/Library/Perl
    /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level
    /System/Library/Perl/Extras/5.8.6
    /Library/Perl/5.8.1
    loopology, Sep 15, 2007
    #1
    1. Advertising

  2. loopology

    Mumia W. Guest

    On 09/15/2007 07:06 AM, loopology wrote:
    > If I run this script:
    >
    > #!/usr/bin/perl
    > use open IN => ":byte";
    > use constant A => 1;
    >
    > on a MacBook Pro (Intel)
    >
    > With perl version 5.8.6 (the pre-installed)
    >
    > I get this error:
    > Can't locate constant.pm in @INC (@INC contains: /sw/lib/perl5 /sw/lib/
    > perl5/dar
    > win /System/Library/Perl/5.8.6/darwin-thread-multi-2level /System/
    > Library/Perl/5
    > ..8.6 /Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/
    > 5.8.6 /Library
    > /Perl /Network/Library/Perl/5.8.6/darwin-thread-multi-2level /Network/
    > Library/Pe
    > rl/5.8.6 /Network/Library/Perl /System/Library/Perl/Extras/5.8.6/
    > darwin-thread-m
    > ulti-2level /System/Library/Perl/Extras/5.8.6 /Library/Perl/5.8.1 .)
    > at ./tst.pl
    > line 3.
    >
    > if I change the line to:
    > use open IN => ":encoding(UTF16-BE)";
    > I get this error:
    > Unrecognized character \xE0 at /System/Library/Perl/5.8.6/constant.pm
    > line 1.
    >
    > In both cases:
    > If I swap the lines, everything runs smoothly.
    >
    > Anyone seen this behaviour?
    > What to do about it?
    > [...]


    I'm able to reproduce this behavior on Debian Linux with Perl 5.8.4 and
    Perl 5.9.4.

    Note, ":byte" is not correct. The correct layer is ":bytes"; however,
    Perl's reaction to the incorrect layer doesn't produce much clarity for
    the programmer.
    Mumia W., Sep 15, 2007
    #2
    1. Advertising

  3. loopology

    Ben Morrow Guest

    Quoth "Mumia W." <>:
    > On 09/15/2007 07:06 AM, loopology wrote:
    > > If I run this script:
    > >
    > > #!/usr/bin/perl
    > > use open IN => ":byte";
    > > use constant A => 1;
    > >
    > > on a MacBook Pro (Intel)
    > >
    > > With perl version 5.8.6 (the pre-installed)
    > >
    > > I get this error:

    <snip>
    > >
    > > if I change the line to:
    > > use open IN => ":encoding(UTF16-BE)";
    > > I get this error:
    > > Unrecognized character \xE0 at /System/Library/Perl/5.8.6/constant.pm
    > > line 1.

    >
    > I'm able to reproduce this behavior on Debian Linux with Perl 5.8.4 and
    > Perl 5.9.4.
    >
    > Note, ":byte" is not correct. The correct layer is ":bytes"; however,
    > Perl's reaction to the incorrect layer doesn't produce much clarity for
    > the programmer.


    In any case, it seems that you should not 'use open' before you use any
    other modules: in no case will applying custom PerlIO layers to the
    module files produce the correct result. This should probably be
    documented in L<open>...

    OP: it's probably worth either dropping open altogether, or switching to
    an INIT block instead of a BEGIN by replacing

    use open IN => ':bytes';

    with

    INIT {
    require open;
    open->import(IN => ':bytes');
    }

    This in then occur later than any 'use' statements (except those in
    string evals); note that you will still have to be careful of 'require'
    statements executed at runtime.

    This could perhaps be considered a bug in Perl: 'require' (or at least
    'require MODULE' rather than 'require "FILE"') should probably *not*
    honour the default PerlIO layers set by open. This may or may not be
    fixable, due to backwards-compatibility...

    Ben
    Ben Morrow, Sep 16, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas
    Replies:
    1
    Views:
    830
    Jonathan Bromley
    May 4, 2004
  2. Jan
    Replies:
    2
    Views:
    1,415
    Mike Treseler
    Dec 16, 2004
  3. Bharat Bhushan

    Appending byte[] to another byte[] array

    Bharat Bhushan, Aug 5, 2003, in forum: Java
    Replies:
    15
    Views:
    40,209
    Roedy Green
    Aug 5, 2003
  4. Jean-Daniel Gamache
    Replies:
    0
    Views:
    411
    Jean-Daniel Gamache
    Jul 14, 2004
  5. Peter
    Replies:
    3
    Views:
    714
    Michael Borgwardt
    Aug 5, 2004
Loading...

Share This Page