in reply to How do I sort an array by hash value?

@id = sort { $lid->{$a} cmp $lid->{$b} } @id
Perl 6 projects - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: How do I sort an array by hash value?
by josh097 (Initiate) on Aug 17, 2009 at 20:53 UTC
    Wow that worked great. Thanks.
    Now what if the array is:
    my @id = ('001=0,2', '010=3', '014=0,0', '060=4', '071-1=3');
    And I want to sort the same way but ignoring the '=' sign and anything after.
        Thanks. I really appreciate your help.
        Here is how I failed:
        @id = sort { $lid->{split(/=/, $a)} cmp $lid->{split(/=/, $b)} } @id;
        Your approach doesn't seem to sort the array unless I change it from
        my $a_ = $a my $b_ = $b
        to
        $a = $a $b = $b
        But if I do that then the values of the array get cut off at the '=' sign (I understand why).
        What does the 'my $a_ = $a' do?