[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Comparing two arrays



On 22 Jul 2000, at 10:10, Bernie Cosell wrote:

hopping on my own not-so-fun thread,

>     my @arrayofstuff ;
>     push @arryofstuff, [ [ key1, key2, key3, key4, ....] , value ]
> 
> Then I want to sort that if there were a fixed number of 'key' values 
> could do as:
>  $a->[0][0] cmp $b->[0][0] or $a->[0][1] cmp $b->[0][1] or ...
> [and then after the sort, a final:
>     map { $_->[1] } [SORTEDLIST].

Well, here's something I played with this afternoon that actually works 
pretty well --- GIVEN: that the 'key's are actually text strings [in 
particular, do NOT have embedded NULL characters], when you make 
@arrayofstuff, instead of the above you make it:
    push @arrayofstuff, [ join("\0", key1, key2, ....), value ]

then you can just do:
    map $_->1, sort { $a->[0] cmp $b->[0] } @arrayofstuff

maybe that's kind of fun [program bumming that an embedded NULL character 
actually works the same as code to "move to the next section of the key"]

  /Bernie\
-- 
Bernie Cosell                     Fantasy Farm Fibers
mailto:bernie@fantasyfarm.com     Pearisburg, VA
    -->  Too many people, too few sheep  <--          

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe