On Jul 13, Beast said:
my @employee = ( [29243, 'john', 'John doe'],
[24322, 'jane', 'Jane doe'],
[27282, 'james', 'James doe']
);
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;
In the sort() block, $a and $b are two elements of the list being
compared. Since the elements are array references, and their first
element is their UID, I've used $a->[0] <=> $b->[0] to compare those two
values. See the documentation for 'sort' (perldoc -f sort) for more
details.
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>