develooper Front page | perl.perl5.porters | Postings from April 2000

BUG: `sort' broken by Date::Manip::ParseDate in 5.005_03

Thread Next
From:
Mark-Jason Dominus
Date:
April 7, 2000 13:29
Subject:
BUG: `sort' broken by Date::Manip::ParseDate in 5.005_03
Message ID:
20000407202936.26076.qmail@plover.com

The attached program demonstrates that either `sort' or Date::Manip is
broken.  

----------------------------------------------------------------
#!/usr/bin/perl 

use Date::Manip;

@msgs = ( "Date: Sat, 18 Mar 2000 15:08:27 -0000\n",
          "Date: Fri, 17 Mar 2000 23:24:53 -0000\n",
          "Date: Sat, 18 Mar 2000 15:01:51 -0000\n",
           "Date: Fri, 17 Mar 2000 17:17:05 EST\n",
           );

@a = sort datecomp (0,1,2,3);

sub datecomp {
  print "Comparing indices $a and $b\n";
  my $da = ParseDate($msgs[$a]);
  my $db = ParseDate($msgs[$b]);
  $da cmp $db;
}
----------------------------------------------------------------

With Date::Manip 5.37 and Perl 5.005_03, the diagnostic statement in
the `datecomp' subroutine prints:

        Comparing indices 1 and 0
        Comparing indices 1 and 0
        Comparing indices 1 and 0

This does not make sense.  The sort comparator should be called at
least once for every item in the list to be sorted.  Since the list to
be sorted is (0,1,2,3) here, the output should have looked something
like this:

        Comparing indices 1 and 0
        Comparing indices 2 and 1
        Comparing indices 3 and 2

for example.

Unsurprisingly, the `sorted' array placed into @a is not in sorted order.

Removing the calls to ParseDate makes the bizarre behavior go away.

I could not think of any way in which Date::Manip could be causing the
bizarre behavior, and traces of its code didn't suggest anything, so
my guess is that `sort' is broken.

I have not tested this program with 5.6.0.


Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.2.12, archname=i586-linux
    uname='linux plover 2.2.12 #10 mon nov 1 17:02:09 est 1999 i586 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=egcs-2.90.29 980515 (egcs-1.0.3 release)
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /shlib /lib /usr/lib
    libs=-lndbm -lgdbm -ldbm -ldb -ldl -lm -lc
    libc=/lib/libc.so.6, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Built under linux
  Compiled at Jan 23 2000 14:17:12
  @INC:
    /usr/lib/perl5/5.00503/i586-linux
    /usr/lib/perl5/5.00503
    /usr/lib/perl5/site_perl/5.005/i586-linux
    /usr/lib/perl5/site_perl/5.005
    .

Thread Next


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