Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.98k stars 559 forks source link

$/ = "" does not work for in-memory files #9002

Closed p5pRT closed 16 years ago

p5pRT commented 17 years ago

Migrated from rt.perl.org#44833 (status was 'resolved')

Searchable as RT44833$

p5pRT commented 17 years ago

From simon.kissane@mq.edu.au

Created by simon.kissane@mq.edu.au

$/ = "" should according to docs​: "Setting to "" will treat two or more consecutive empty lines as a single empty line."

Works fine when write file out to disk and read it back in but fails with in memory files\, even though they should be equivalent.

Reproduce script​: ========= BEGIN REPRODUCE SCRIPT ============= #!/usr/bin/perl -w =head1 perlbug.pl

This script demonstrates a perl bug - $/ = "" does not work properly for in-memory files.

=cut use strict; use Data​::Dumper; use File​::Temp qw(tempfile);

my $s = \<\<END; This is the contents of paragraph 1

This is the contents of paragraph 2

END

$/ = "";

my ($tmp\, $filename) = tempfile(); print $tmp $s; flush $tmp;

my $fh1; open($fh1\, "\<"\, $filename); my $o1 = scalar \<$fh1>;

my $fh2; open($fh2\, "\<"\, \$s); my $o2 = scalar \<$fh2>;

print Dumper [ $o1\, $o2]; ========= END REPRODUCE SCRIPT =============

Perl Info ``` Flags: category=core severity=medium This perlbug was built using Perl v5.8.5 in the Red Hat build system. It is being executed now by Perl v5.8.5 - Sat Oct 7 08:32:04 PDT 2006. Site configuration information for perl v5.8.5: Configured by Red Hat, Inc. at Sat Oct 7 08:32:04 PDT 2006. Summary of my perl5 (revision 5 version 8 subversion 5) configuration: Platform: osname=linux, osvers=2.6.9-34.elsmp, archname=i386-linux-thread-multi uname='linux ca-build10 2.6.9-34.elsmp #1 smp fri feb 24 16:54:53 est 2006 i686 athlon i386 gnulinux ' config_args='-des -Doptimize=-O2 -g -pipe -m32 -march=i386 -mtune=pentium4 -Dversion=5.8.5 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dinc_version_list=5.8.4 5.8.3 5.8.2 5.8.1 5.8.0' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm', optimize='-O2 -g -pipe -m32 -march=i386 -mtune=pentium4', cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm' ccversion='', gccversion='3.4.6 20060404 (Red Hat 3.4.6-3.1)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='gcc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc libc=/lib/libc-2.3.4.so, so=so, useshrplib=true, libperl=libperl.so gnulibc_version='2.3.4' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE' cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.8.5: /usr/lib/perl5/5.8.5/i386-linux-thread-multi /usr/lib/perl5/5.8.5 /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl/5.8.2 /usr/lib/perl5/site_perl/5.8.1 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.2/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl/5.8.4 /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl/5.8.2 /usr/lib/perl5/vendor_perl/5.8.1 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl . Environment for perl v5.8.5: HOME=/ora/sw/dirbuild LANG=en_US.UTF-8 LANGUAGE (unset) LD_LIBRARY_PATH=/ora/sw/rdbms/10.2.0/lib LOGDIR (unset) PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/ora/sw/dirbuild/bin PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 17 years ago

From abe@ztreet.demon.nl

-----BEGIN PGP SIGNED MESSAGE----- Hash​: SHA1

simon.kissane@​mq.edu.au (via RT) wrote​:

[snip]

$/ = "" should according to docs​: "Setting to "" will treat two or more consecutive empty lines as a single empty line."

Works fine when write file out to disk and read it back in but fails with in memory files\, even though they should be equivalent.

This looks to be fixed from 5.8.8

Reproduce script​: ========= BEGIN REPRODUCE SCRIPT ============= #!/usr/bin/perl -w =head1 perlbug.pl

This script demonstrates a perl bug - $/ = "" does not work properly for in-memory files.

=cut use strict; use Data​::Dumper; use File​::Temp qw(tempfile);

my $s = \<\<END; This is the contents of paragraph 1

This is the contents of paragraph 2

END

$/ = "";

my ($tmp\, $filename) = tempfile(); print $tmp $s; flush $tmp;

my $fh1; open($fh1\, "\<"\, $filename); my $o1 = scalar \<$fh1>;

my $fh2; open($fh2\, "\<"\, \$s); my $o2 = scalar \<$fh2>;

print Dumper [ $o1\, $o2];

~/klad$ perl588 44833.pl $VAR1 = [   'This is the contents of paragraph 1

'\,   'This is the contents of paragraph 1

'   ];

HTH + Good luck\,

Abe - -- Merijn> We *do* need tests (I am not good in tests​: hint hint)

Calling all happy passive readers of perl5-porters - submit a patch\, get your name into the AUTHORS file​: fame\, immortality and more spam.   -- Nicholas Clark on p5p @​ 2004-01-22 -----BEGIN PGP SIGNATURE----- Version​: GnuPG v1.4.7 (Darwin) Comment​: Using GnuPG with Mozilla - http​://enigmail.mozdev.org

iD8DBQFGzF090u0nt7xxiCIRAsfhAJ0TgzYbV6Mf3/vRGVrcnQOhFnSbTACfZaHC 4tI7kCbm1rlnrzvt6yAa3WQ= =i4uX -----END PGP SIGNATURE-----

p5pRT commented 17 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 16 years ago

p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'