Oops.
Sorry
I had a bug in my perl script.
The compare functions is working perfectly.
I beg pardon for my mistake.
By the way, but maybe this is off topic and it's strictly a Perl question, I've really seen the behaviour described: the compare function exiting at $i=0 element.
Can someone explain to me how it works, really ?
Thanks


Francesco


On 29/09/2010 09:12, Sormariano wrote:

Hello
I'm trying to sort an array of dates with milliseconds
In the DataTime.pm file, the subroutine compare has the following statements

foreach my $i ( 0..2 )
    {
        return $dt1_components[$i] <=> $dt2_components[$i]
            if $dt1_components[$i] != $dt2_components[$i]
    }

so, my datas have:
dt1_components[0]=733773
dt1_components[0]=55196
dt1_components[0]=631723
and
dt2_components[0]=733773
dt2_components[0]=55196
dt2_components[0]=631776

So, due to those statements, the comparison ends with dt1_components[0]=dt1_components[1] and the compare subroutine says to me that the 2 datas are the same, but it's not true, since they differs in milliseconds

The problem is that if statement on the 2nd line of code is not on the same line of the return line, there is a return on them.
So the return statement is soon executed on the element $i=0
I fixed it putting the if statement on the same line of the return statement and now it works.

If some of you confirm this problem I could open a ticket.

Thanks

Francesco





Reply via email to