develooper Front page | perl.perl5.porters | Postings from December 2016

[perl #130335] sort{$a<=>$b} fails to sort occasionally

Thread Previous
From:
Takeshi Kitahara via RT
Date:
December 19, 2016 00:33
Subject:
[perl #130335] sort{$a<=>$b} fails to sort occasionally
Message ID:
rt-4.0.24-9054-1481865392-239.130335-15-0@perl.org
I saw a similar issue.
When I coded;
my $a = undef;
before sort line, the sort doesn't work, however, without 'my' statement, it works.
Probably it might be a bug.

On Mon, 12 Dec 2016 19:33:59 -0800, tails.saito@gmail.com wrote:
> This is a bug report for perl from tails.saito@gmail.com,
> generated with the help of perlbug 1.40 running under perl 5.22.2.
> 
> Greetings,
> 
> sort{$a<=>$b} fails to sort a list of strings numerically in some
> cases.
> Here is an example.
> 
> Code:
> @in = (
>     "0",
>     "20000000000000001",
>     "20000000000000000" );
> @result = sort {$a<=>$b} @in;
> print join "\n", @result;
> 
> Output:
> 0
> 20000000000000001
> 20000000000000000
> 
> However, if I use {0;$a<=>$b} instead of {$a<=>$b},
> I get a correct result.
> 
> Code:
> @in = (
>     "0",
>     "20000000000000001",
>     "20000000000000000" );
> @result = sort {0;$a<=>$b} @in;
> print join "\n", @result;
> 
> Output:
> 0
> 20000000000000000
> 20000000000000001
> 
> I confirmed the above matter happens with:
> perl v5.22.2 cygwin-thread-multi-64int; and
> perl v5.16.3 on CentOS.
> 
> I noticed the above matter does NOT happen with:
> Debian perl-5.14.2-9.
> 
> Thank you for your attention.
> ---
> Flags:
>     category=core
>     severity=medium
> ---
> Site configuration information for perl 5.22.2:
> 
> Configured by ASSI at Sat Apr 30 15:59:30 CEST 2016.
> 
> Summary of my perl5 (revision 5 version 22 subversion 2)
> configuration:
> 
> Platform:
>   osname=cygwin, osvers=2.5.1(0.29753), archname=cygwin-thread-multi-
> 64int
>   uname='cygwin_nt-6.3-wow cygwin 2.5.1(0.29753) 2016-04-21 22:12
> i686 cygwin '
>   config_args='-des -Dprefix=/usr -Dmksymlinks
> -Darchname=i686-cygwin-threads-64int -Dlibperl=cygperl5_22.dll
> -Dcc=gcc -Dld=g++ -Accflags=-ggdb -O2 -pipe
> -Wimplicit-function-declaration
> -fdebug-prefix-
> map=/mnt/share/maint/perl.x86/build=/usr/src/debug/perl-5.22.2-1
> -fdebug-prefix-map=/mnt/share/maint/perl.x86/src/perl-
> 5.22.2=/usr/src/debug/perl-5.22.2-1
> -fwrapv'
>   hint=recommended, useposix=true, d_sigaction=define
>   useithreads=define, usemultiplicity=define
>   use64bitint=define, use64bitall=undef, uselongdouble=undef
>   usemymalloc=n, bincompat5005=undef
> Compiler:
>   cc='gcc', ccflags ='-DPERL_USE_SAFE_PUTENV -D_GNU_SOURCE
> -U__STRICT_ANSI__ -ggdb -O2 -pipe -Wimplicit-function-declaration
> -fdebug-prefix-
> map=/mnt/share/maint/perl.x86/build=/usr/src/debug/perl-5.22.2-1
> -fdebug-prefix-map=/mnt/share/maint/perl.x86/src/perl-
> 5.22.2=/usr/src/debug/perl-5.22.2-1
> -fwrapv -fno-strict-aliasing -fstack-protector-strong
> -D_FORTIFY_SOURCE=2',
>   optimize='-O3',
>   cppflags='-DPERL_USE_SAFE_PUTENV -D_GNU_SOURCE -U__STRICT_ANSI__
> -ggdb -O2 -pipe -Wimplicit-function-declaration
> -fdebug-prefix-
> map=/mnt/share/maint/perl.x86/build=/usr/src/debug/perl-5.22.2-1
> -fdebug-prefix-map=/mnt/share/maint/perl.x86/src/perl-
> 5.22.2=/usr/src/debug/perl-5.22.2-1
> -fwrapv -fno-strict-aliasing -fstack-protector-strong'
>   ccversion='', gccversion='5.3.0', gccosandvers=''
>   intsize=4, longsize=4, ptrsize=4, doublesize=8,
> byteorder=12345678, doublekind=3
>   d_longlong=define, longlongsize=8, d_longdbl=define,
> longdblsize=12, longdblkind=3
>   ivtype='long long', ivsize=8, nvtype='double', nvsize=8,
> Off_t='off_t', lseeksize=8
>   alignbytes=8, prototype=define
> Linker and Libraries:
>   ld='g++', ldflags =' -Wl,--enable-auto-import
> -Wl,--export-all-symbols -Wl,--enable-auto-image-base
> -fstack-protector-strong'
>   libpth=/usr/lib
>   libs=-lpthread -lgdbm -ldb -ldl -lcrypt -lgdbm_compat
>   perllibs=-lpthread -ldl -lcrypt
>   libc=/usr/lib/libcygwin.a, so=dll, useshrplib=true,
> libperl=cygperl5_22.dll
>   gnulibc_version=''
> Dynamic Linking:
>   dlsrc=dl_dlopen.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
>   cccdlflags=' ', lddlflags=' --shared  -Wl,--enable-auto-import
> -Wl,--export-all-symbols -Wl,--enable-auto-image-base
> -fstack-protector-strong'
> 
> 
> ---
> @INC for perl 5.22.2:
>     /usr/lib/perl5/site_perl/5.22/i686-cygwin-threads-64int
>     /usr/lib/perl5/site_perl/5.22
>     /usr/lib/perl5/vendor_perl/5.22/i686-cygwin-threads-64int
>     /usr/lib/perl5/vendor_perl/5.22
>     /usr/lib/perl5/5.22/i686-cygwin-threads-64int
>     /usr/lib/perl5/5.22
>     .
> 
> ---
> Environment for perl 5.22.2:
>     HOME=/home/user
>     LANG=ja_JP.utf-8
>     LANGUAGE (unset)
>     LD_LIBRARY_PATH (unset)
>     LOGDIR (unset)
>     PERL_BADLANG (unset)
>     SHELL=/bin/bash


-- 
TakeshiKitahara

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=130335

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About