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

This works in Perl 5.12.3 (Slackware Linux 13.37 64 bit):

#!/usr/bin/perl use strict; use warnings; my $text="Hello World\n123\njust a short text\n"; my $r=\$text; open my $f,'<',$r or die "open failed: $!"; print while <$f>; close $f;

Output:

Hello World 123 just a short text

Adding a layer causes a file not found error:

#!/usr/bin/perl use strict; use warnings; my $text="Hello World\n123\njust a short text\n"; my $r=\$text; open my $f,'<:raw',$r or die "open failed: $!"; print while <$f>; close $f;

Output:

open failed: No such file or directory at test.pl line 9.

The same code worked flawlessly on Perl 5.10.0 (Slackware Linux 13.0 32 bit).

Bug in 5.12.3? Or did I miss some documented change?

perl -V:

Summary of my perl5 (revision 5 version 12 subversion 3) configuration +: Platform: osname=linux, osvers=2.6.35.10, archname=x86_64-linux-thread-multi uname='linux midas64 2.6.35.10 #2 smp thu jan 6 19:06:19 cst 2011 +x86_64 amd athlon(tm) ii x2 235e processor authenticamd gnulinux ' config_args='-de -Dprefix=/usr -Dvendorprefix=/usr -Dcccdlflags=-f +PIC -Dinstallprefix=/usr -Dlibpth=/usr/local/lib64 /usr/lib64 /lib64 +-Doptimize=-O2 -fPIC -Dusethreads -Duseithreads -Dpager=/usr/bin/less + -isr -Dinc_version_list=5.12.2 5.12.1 5.12.0 5.10.1 5.10.0 5.8.8 5.8 +.7 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 -Darchname=x86_64-linux' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=und +ef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing + -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_ +FILE_OFFSET_BITS=64', optimize='-O2 -fPIC', cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -f +stack-protector -I/usr/local/include' ccversion='', gccversion='4.5.2', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +6 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='cc', ldflags =' -fstack-protector' libpth=/usr/local/lib64 /usr/lib64 /lib64 libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc libc=/lib64/libc-2.12.2.so, so=so, useshrplib=false, libperl=libpe +rl.a gnulibc_version='2.12.2' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -fPIC -fstack-protector +' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_64_ +BIT_ALL USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_PERL_ATOF USE_REENTRANT_API Built under linux Compiled at Jan 26 2011 12:39:46 @INC: /usr/lib64/perl5/site_perl/5.12.3/x86_64-linux-thread-multi /usr/lib64/perl5/site_perl/5.12.3 /usr/lib64/perl5/vendor_perl/5.12.3/x86_64-linux-thread-multi /usr/lib64/perl5/vendor_perl/5.12.3 /usr/lib64/perl5/5.12.3/x86_64-linux-thread-multi /usr/lib64/perl5/5.12.3 /usr/lib64/perl5/site_perl /usr/lib64/perl5/vendor_perl .

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re: Perl 5.12: layers and opening scalars as file handles
by Tux (Canon) on Sep 01, 2011 at 10:02 UTC

    I'll post this to the porters list, as using "<:encoding(utf-8)" does not fail.

    update: This was fixed in version 5.13.10:

    41 0.00918 0.010 0.000 FAIL base/tperl5.11.3 42 0.01080 0.010 0.000 FAIL base/perl5.11.4 43 0.00798 0.000 0.000 FAIL base/tperl5.11.4 44 0.00445 0.000 0.000 FAIL base/perl5.11.5 45 0.01272 0.010 0.010 FAIL base/tperl5.11.5 46 0.00596 0.010 0.000 FAIL base/perl5.12.0 47 0.00458 0.000 0.000 FAIL base/tperl5.12.0 48 0.00418 0.010 0.000 FAIL base/perl5.12.1 49 0.00460 0.000 0.000 FAIL base/tperl5.12.1 50 0.00399 0.000 0.000 FAIL base/perl5.12.2 51 0.00468 0.000 0.000 FAIL base/tperl5.12.2 52 0.00394 0.010 0.000 FAIL base/perl5.12.3 53 0.00475 0.000 0.000 FAIL base/tperl5.12.3 54 0.00425 0.000 0.010 FAIL base/perl5.12.4 55 0.00952 0.000 0.000 FAIL base/tperl5.12.4 56 0.00676 0.000 0.010 FAIL base/perl5.13.0 57 0.00692 0.000 0.000 FAIL base/tperl5.13.0 58 0.00473 0.000 0.000 FAIL base/perl5.13.1 59 0.00498 0.010 0.000 FAIL base/tperl5.13.1 60 0.00446 0.000 0.000 FAIL base/perl5.13.2 61 0.00493 0.010 0.000 FAIL base/tperl5.13.2 62 0.00676 0.000 0.000 FAIL base/perl5.13.3 63 0.00482 0.000 0.000 FAIL base/tperl5.13.3 64 0.00447 0.000 0.000 FAIL base/perl5.13.4 65 0.00491 0.010 0.000 FAIL base/tperl5.13.4 66 0.00452 0.000 0.000 FAIL base/perl5.13.5 67 0.00540 0.000 0.000 FAIL base/tperl5.13.5 68 0.00401 0.000 0.010 FAIL base/perl5.13.6 69 0.00479 0.000 0.000 FAIL base/tperl5.13.6 70 0.00408 0.000 0.000 FAIL base/perl5.13.7 71 0.00519 0.000 0.000 FAIL base/tperl5.13.7 72 0.00443 0.000 0.000 FAIL base/perl5.13.8 73 0.00508 0.010 0.000 FAIL base/tperl5.13.8 74 0.00458 0.000 0.000 FAIL base/perl5.13.9 75 0.00483 0.010 0.010 FAIL base/tperl5.13.9 76 0.00448 0.000 0.000 PASS base/perl5.13.10 77 0.00503 0.000 0.000 PASS base/tperl5.13.10 78 0.00434 0.010 0.000 PASS base/perl5.13.11 79 0.00508 0.000 0.000 PASS base/tperl5.13.11 80 0.00435 0.000 0.000 PASS base/perl5.14.0 81 0.00459 0.000 0.010 PASS base/tperl5.14.0 82 0.00493 0.000 0.000 PASS base/perl5.14.1 83 0.01190 0.000 0.000 PASS base/tperl5.14.1 84 0.00434 0.000 0.000 PASS base/perl5.15.0 85 0.00484 0.000 0.000 PASS base/tperl5.15.0 86 0.00447 0.010 0.000 PASS base/perl5.15.1 87 0.00484 0.010 0.000 PASS base/tperl5.15.1 88 0.00455 0.000 0.000 PASS base/perl5.15.2 89 0.00501 0.000 0.010 PASS base/tperl5.15.2

    Enjoy, Have FUN! H.Merijn
Re: Perl 5.12: layers and opening scalars as file handles
by Eliya (Vicar) on Sep 01, 2011 at 09:00 UTC

    It doesn't work for me with any of 5.8.4, 5.10.0, 5.10.1, 5.12.2 and 5.12.3 (those are the ones I have available for testing here). And IIRC, it never worked with any vanilla build of perl. Maybe your Slackware 5.10.0 had a specific patch applied?

    I dimly recall there was a thread here a couple of years ago that discussed the issue — but I can't find it right now... (maybe someone else will) .

    Upd: I think this is what I remembered: Clash between IO layers and "in memory" files?.

      It doesn't work for me with any of 5.8.4, 5.10.0, 5.10.1, 5.12.2 and 5.12.3 (those are the ones I have available for testing here). And IIRC, it never worked with any vanilla build of perl.

      So the program I'm debugging right now runs into code that was never executed on the old installation. Grrrr....

      Maybe your Slackware 5.10.0 had a specific patch applied?

      No, Slackware usually builds perl without extra patches. In SL13.0, there is a trivial multilib patch, but it is not applied on a 32 bit build. (Update: Same situation with 13.37: trivial multilib patch, applied only on x86_64)

      I think this is what I remembered: Clash between IO layers and "in memory" files?.

      Looks familiar. 4 years old and still not working. Oh well, it seems the real problem with the program is somewhere else.

      Thanks for testing, and for the link.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Perl 5.12: layers and opening scalars as file handles
by Tux (Canon) on Sep 01, 2011 at 09:44 UTC

    I'll post this to the porters list, as using "<:encoding(utf-8)" does not fail.


    Enjoy, Have FUN! H.Merijn
Re: Perl 5.12: layers and opening scalars as file handles
by Anonymous Monk on Sep 01, 2011 at 10:39 UTC

    Difference between 5.12.2 and 5.14.1 if you set PERLIO_DEBUG=

    $ perl -le " open my $fh => '<:raw', \'blah' "
    -e:1 scalar => 0x12113000 -e:1 raw => 0x68b5c6c0 -e:1 Layer 1 is raw -e:1 openn(raw,':raw','r',-1,0,0,0,1,0x3f5230) -e:1 Layer 0 is unix -e:0 Destruct 0x3f3f7c ...
    -e:1 scalar => 64fc3000 -e:1 raw => 66c53840 -e:1 Layer 1 is raw -e:1 openn(raw,':raw','r',-1,0,0,00000000,1,003f5230) -e:1 Layer 0 is unix -e:1 Layer 0 is scalar -e:1 PerlIO_push f=009941dc scalar r 0099a904 -e:1 PerlIO_push f=009941dc raw r 003f47a8 -e:1 :raw f=009941dc :scalar -e:0 PerlIO_pop f=009941dc scalar -e:0 Destruct 003f4004 ...

    On the other hand, if you use

    $ perl -le " open my $fh => '<:encoding(UTF-8)', \'blah' "
    there is no difference aside from the usual memaddr
    -e:1 encoding => 0x1076000 -e:1 Layer 1 is encoding -e:1 openn(encoding,':encoding(UTF-8)','r',-1,0,0,0,1,0x3f5208) -e:1 Layer 0 is unix -e:1 Layer 0 is scalar -e:1 PerlIO_push f=0x9b4024 scalar r 0x9ba20c -e:1 PerlIO_push f=0x9b4024 encoding r 0x9b9c4c -e:0 PerlIO_pop f=0x9b4024 encoding -e:0 PerlIO_pop f=0x9b4024 scalar -e:0 Destruct 0x3f3f5c
Re: Perl 5.12: layers and opening scalars as file handles
by ikegami (Patriarch) on Sep 01, 2011 at 18:19 UTC

    The documentation says "The :raw layer is defined as being identical to calling binmode($fh)"

    In reality, :raw removes all layers. That includes the one the low level ones such as the one that redirects the IO to a var.

    There is definitely a bug, but I don't know if it's in the docs, in the implementation or in both.

Re: Perl 5.12: layers and opening scalars as file handles
by Anonymous Monk on Sep 01, 2011 at 10:01 UTC

    Bugin 5.12.3? Or did I miss some documented change?

    Neither, both, and the other :)

    Maybe your perl-5.10.0 version did not

    $ perl -V:useperlio useperlio='define';
    so it did not trigger this croak

    ActivePerl 5.8.9 croaks for me on win32, so it would appear, it always croaked

      perl -V output on SL13.0, 32 bit

      Summary of my perl5 (revision 5 version 10 subversion 0) configuration +: Platform: osname=linux, osvers=2.6.24.7-smp, archname=i486-linux-thread-mult +i uname='linux midas 2.6.24.7-smp #1 smp sun sep 7 20:00:12 cdt 2008 + i686 amd athlon(tm) 64 x2 dual core processor 5200+ authenticamd gnu +linux ' config_args='-de -Dprefix=/usr -Dvendorprefix=/usr -Dcccdlflags=-f +PIC -Dinstallprefix=/usr -Doptimize=-O2 -march=i486 -mtune=i686 -Duse +threads -Duseithreads -Dpager=/usr/bin/less -isr -Dinc_version_list=5 +.8.8 5.8.7 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 -Darchname=i486- +linux' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=und +ef use64bitint=undef, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing + -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=6 +4', optimize='-O2 -march=i486 -mtune=i686', cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -I +/usr/local/include' ccversion='', gccversion='4.2.4', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +2 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc libc=/lib/libc-2.7.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.7' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -march=i486 -mtune=i686 + -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_ITH +READS USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API Built under linux Compiled at Sep 8 2008 02:01:08 %ENV: PERL_UNICODE="SDL" @INC: /usr/lib/perl5/5.10.0/i486-linux-thread-multi /usr/lib/perl5/5.10.0 /usr/lib/perl5/site_perl/5.10.0/i486-linux-thread-multi /usr/lib/perl5/site_perl/5.10.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.10.0/i486-linux-thread-multi /usr/lib/perl5/vendor_perl/5.10.0 /usr/lib/perl5/vendor_perl .

      And for useperlio:

      perl -V:useperlio useperlio='define';

      And, unfortunately, open with a :raw layer also fails on SL13.0 i.e. perl 5.10.0. The code was simply never reached on SL13.0.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Perl 5.12: layers and opening scalars as file handles
by Khen1950fx (Canon) on Sep 01, 2011 at 18:31 UTC
    I tried it with '<:raw' and got "no such file". I tried it with '<&=:raw' and got "Bad filehandle". A simple '<' did the trick. I added binmode also.  my $r = \$text; was a noop. Bettter to do my $r = text and use \$r in the open. When I used \$text, nothing printed.
    #!/usr/bin/perl -slw use strict; my $text = "Hello World\n123\na short text\n"; my $r = $text; open my $fh, '<', \$r or die $!; my @lines = <$fh>; binmode $fh, ":raw"; close $fh or die "unable to close: $!"; print @lines;