Jeff 'japhy' Pinyan <mailto:[EMAIL PROTECTED]> wrote:
> On Jul 13, Beast said:
> 
>> Jeff 'japhy' Pinyan wrote:
>>> 
>>>> Is there any builtin function in perl to sort the above array based
>>>> on uid, username or fulname?
>>> 
>>> There is a built-in function to sort a list, yes.  But the mechanism
>>> by which to sort the list is, in this case, up to you to provide. 
>>> This works: 
>>> 
>>>   my @sorted = sort {
>>>     $a->[0] <=> $b->[0]
>>>   } @employees;
>>> 
>> 

Hey, This will sort only numbers. Will have no effect if the values have
text.

>> However, is this scalable if, for example list is more than 5000 ?
> 
> Sure, it's scalable... I believe perl uses a mergesort nowadays,
> which is better on larger lists anyway.  Regardless, given the data
> you showed us, this is the simplest and shortest (and most likely
> fastest) way to sort it based on a given index.   

For more information...

[...]

    use sort 'stable';          # guarantee stability
    use sort '_quicksort';      # use a quicksort algorithm
    use sort '_mergesort';      # use a mergesort algorithm
    use sort 'defaults';        # revert to default behavior
    no  sort 'stable';          # stability not important

    use sort '_qsort';          # alias for quicksort

    my $current = sort::current();      # identify prevailing algorithm

[...]

--Ankur

Bad style destroys an otherwise superb program.

--
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