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

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



Andy Jacobs <andyj@microsoft.com> wrote:

> This would probably be MUCH slower... but it's kind of
> compact and fun.
> 
> (sort map {length} @data)[-1];

Not quite as compact when done correctly, though:

  (sort {$a <=> $b} map {length} @data)[-1];

or

  (sort {$b <=> $a} map {length} @data)[0];

Your version works only if no string is longer than nine 
characters.

-- 
Keith C. Ivey <kcivey@cpcug.org>
http://cpcug.org/user/kcivey/
Washington, DC

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