in reply to Sort Question (Again) :(

my @sorted_list = map { $_->[0] } sort { $a->[1] cmp $b->[1] or $a->[2] cmp $b->[2] } map { [ $_, (split /\t/)[3,4] ] } @database_in;

I made a few stylistic changes too :)

Update: Removed $_ from split. Hofmator is right - it was an artifact from the refactoring :(

--
<http://www.dave.org.uk>

"The first rule of Perl club is you don't talk about Perl club."

Replies are listed 'Best First'.
Re: Re: Sort Question (Again) :(
by Hofmator (Curate) on Oct 19, 2001 at 20:28 UTC

    ++davorg, I just wanted to suggest the same thing, including the same stylistic changes :). But where do you see the benefit of giving split the explicit $_, instead of simply (split /\t/)[3,4]?

    -- Hofmator

Re: Re: Sort Question (Again) :(
by LostS (Friar) on Oct 19, 2001 at 20:34 UTC
    HEY.. I found out why Jeff was coming before Jayne... And my god that can be a loaded answer or question... Anyways...
    The problem is Jeff has a space in front of his name... Now how would I say ignore the space in the front of all fields and then sort??


    -----------------------
    Billy S.
    Slinar Hardtail - Guildless
    Datal Ephialtes - Guildless
    RallosZek.Net Admin/WebMaster
    Aerynth.Net Admin/WebMaster

    perl -e '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat! +\n"; } else { print "Thats a dog\n"; } print "\n";'

      Change the split criteria to remove whitespace as well. Building on davorg's code:

      my @sorted_list = map { $_->[0] } sort { $a->[1] cmp $b->[1] or $a->[2] cmp $b->[2] } map { [ $_, (split /\t\s*/)[3,4] ] } @database_in;

      Blessed Be
      The Pixel

      See answer below.
Re: Re: Sort Question (Again) :(
by LostS (Friar) on Oct 19, 2001 at 20:28 UTC
    Just tried exactly what you put... and this is the order it gave me...

    Jeff Williams
    Jayne Williams
    Phil Williams

    Doesn't Jayne come before Jeff??

    -----------------------
    Billy S.
    Slinar Hardtail - Guildless
    Datal Ephialtes - Guildless
    RallosZek.Net Admin/WebMaster
    Aerynth.Net Admin/WebMaster

    perl -e '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat! +\n"; } else { print "Thats a dog\n"; } print "\n";'
      Yeah, but 'Wiliams' comes before 'Williams' ... :-)

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

        Typo :-P
        They are all Williams :-/

        -----------------------
        Billy S.
        Slinar Hardtail - Guildless
        Datal Ephialtes - Guildless
        RallosZek.Net Admin/WebMaster
        Aerynth.Net Admin/WebMaster

        perl -e '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat! +\n"; } else { print "Thats a dog\n"; } print "\n";'