More 'n more bugs.

Ovid on 2004-02-11T19:58:19

Of course this won't work. Silly me.

    my $line_no = 1;
    @expected_data =
        sort {
            $a->[1] <=> $b->[1]
                ||
            Foo::compare($a->[5], $b->[5])
                || 
            $a->[2] <=> $b->[2]
        }
        map { unshift @$_ => $line_no++ }
            @expected_data;


sort isn't working on a list of array refs

jjohn on 2004-02-15T12:09:23

I think I see a couple of problems, but I'd need to see the whole code to get it.

map generates a simple list, but the sort code appears to be working on a list of array reference. It looks like you were trying to build a hash with map. However, the sort code thinks that each element of the list is an array reference. The "keys" of the "hash" may be array refs (which would be super weird), but the "values" certainly are not.

This is very functional (that is lisp-like) code. Perhaps you might consider turning up the verbosity by using "structures" (hashes)? It will make the sort code a little by more transparent, I reckon.

Re:sort isn't working on a list of array refs

Ovid on 2004-02-15T18:49:37

This illustrates the problem:

perl -e 'print map { unshift @x => 1 } 1 .. 3'

That will print "123". The return value of unshift is the number of elements in the array after unshifting.