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

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



On Thu, Jun 24, 1999 at 09:57:16PM -0400, Bill Jones wrote:
> >From: John Porter <jdporter@min.net>
> >Date: Thu, Jun 24, 1999, 10:59 AM
> >
> 
> >
> > @a[ map { length } @data ] = ();
> >
> > print $#a;
> >
> 
> :]
> 
> It looks good - but, why was an array used for @data?

Because you need to compare the lengths of all the strings, and find the
longest one.


> I couldn't get it to test all the elements, so I
> just used $data...

So you're only getting the length of a single string.


> @a[ map { length } $data ] = ();
> print $#a;

This is a fun way to get the length of $data, but the goal was to get the
length of the longest string in @data.


> Also, I found it funny (while I was trying to walk thru
> array elements) that the following prints nothing:
> 
> (@a[ map { length } $data ] = ()) ? print $#a : print '';
> 
> Seems to me that while the first portion does set $#a,
> it returns 0 (zero) when it's done...

Actually, it returns (), because that's what was being assigned.
List assignment returns the list of values that was assigned.


Ronald


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