> Hello,

Hi,
 
> I have an array of names and would like to sort the array by 
> the length of the name but am having difficulty. 
> 
> Any suggestions ? 

if you want to sort in ascending order
@sorted = sort { length($a) <=> length($b) } @unsorted; 

or if in descending order
@sorted = sort { length($b) <=> length($a) } @unsorted; 

perldoc -f sort will give you many useful examples.

--Ankur



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to