It's working fine and thanks for your help---hopefully my users will welcome the difference.
Thanks again. -----Original Message----- From: James Edward Gray II [mailto:[EMAIL PROTECTED] Sent: Thursday, February 19, 2004 4:42 PM To: Smith Jeff D Cc: '[EMAIL PROTECTED]' Subject: Re: An Old Question on Sorting Hash of Arrays by Array element an d th en by key On Feb 19, 2004, at 3:20 PM, Smith Jeff D wrote: > Thanks, I must have missed it--I'll be getting back to it tomorrow > morning > to see what I missed in the original response. I thought I had run as > printed below. No worries. You probably did run my original response, which was flawed. Mark gave a fix for it shortly after I posted it. Then Rob pointed out that it was ignoring your case insensitive request today. All their suggestions are included below. The Moral: Don't use the original message. Use this one. > Anyway, thank for the help...I think I may have braced when I should > have > paren'd... It so simple when someone else does it first.... I was > trying to > nest the sorts rather > than logically or'ing them together and it wasn't working. Oring sort() conditions is a common Perl idiom. Now you know. ;) James > #!/usr/bin/perl > > use strict; > use warnings; > > # create some data > my %HofA = ( orange => ['ZZZ', 'ANDY'], > red => ['AAA', 'AL'], > blue => ['mmm','Betty'], > yellow => ['aaa', 'ZEUS'], > green => ['DDD','Mary Joe'], > violet => ['MMM','Hugo'] ); > > # sort it > my @ordered_keys = sort { lc($HofA{$a}[0]) cmp lc($HofA{$b}[0]) > || > lc($a) cmp lc($b) } keys > %HofA; > > # print it > foreach (@ordered_keys) { > print "$HofA{$_}[0], $_, $HofA{$_}[1]\n"; > } > > __END__ > > You'll notice that the above is really just a summary of this thread. > When I run it, I get: > > AAA, red, AL > aaa, yellow, ZEUS > DDD, green, Mary Joe > mmm, blue, Betty > MMM, violet, Hugo > ZZZ, orange, ANDY > > Which is the output you requested in your original message. > > Hope that helps. > > James > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
