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

RE: [FWP] Finding the length of the longest string



> From: John Porter [mailto:jdporter@min.net]
> Sent: Thursday, June 24, 1999 08:00
> To: fwp@technofile.org
> Subject: Re: [FWP] Finding the length of the longest string
> 
> Larry Rosler wrote:
...
> > my $len = "";
> > $len ^= $_ for @data;
> > $len = length $len;
> 
> @a[ map { length } @data ] = ();
> print $#a;
> 
> Hoo!

There's a strong analogy to the code I wrote -- extend a string by xor
to the length of the longest string seen so far.  Your code extends an
array.  It is somewhat slower than the xor or the max approaches, but
much faster than the sorts.

I thought this was a fun problem -- too much fun for c.l.p.misc.  :-)

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com

==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org