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

Re: [FWP] Comparing two arrays



Well, there's always this (my arrays go from the shift end, but the
replacement should work, too):

  sub acmp {
    my @a = @{$_[0]};
    my @b = @{$_[1]};
    ((shift @a) cmp (shift @b)) || acmp(\@a,\@b);
  }

This only works if the two arguments are never completely equal.  And
if they're different lengths, neither should be a prefix of the
other.  I don't know if that makes it more fun, or less.

Oh, and you'll need to wrap it to use with sort (which doesn't like
recursive subs according to its definition (not that I understand how
to write a useful recursive sub using only $a and $b as args)).
-- 
Ariel Scolnicov        |"GCAAGAATTGAACTGTAG"            | ariels@compugen.co.il
Compugen Ltd.          |Tel: +972-2-6795059 (Jerusalem)	\ We recycle all our Hz
72 Pinhas Rosen St.    |Tel: +972-3-7658514 (Main office)`---------------------
Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555    http://3w.compugen.co.il/~ariels

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