Hi all
I'm trying to update a script originally written by someone else (yeehaw),
and I'm having troubles with the sorting routine.
here's the code snippet.....
sub list_files {
#($name, $type, $size, $mtime, $mode) = @$_;
@sites = keys %das_sites;
@sites = sort { lc($a) cmp lc($b) } @sites
if $form{sort} eq 'Site';
@sites = map { $_->[0] }
sort { $b->[1] cmp $a->[1] ||
lc($a->[0]) cmp lc($b->[0]) }
map { [$_, $info_dirs->{$_}->{'owner'} ] }
@sites
if $form{sort} eq 'owner1;
@sites = map { $_->[0] }
sort { $a->[1] cmp $b->[1] ||
lc($a->[0]) cmp lc($b->[0]) }
map { [$_, $info_dirs->{$_}->{'owner'} || 'z' ] }
@sites
if $form{sort} eq 'owner2';
print <<HTML;
<html>
<head>
.............
The second two sorts are the ones I'm interested in. It sorts first by the
owner ($b->[1] cmp $a->[1]), then by the name (lc($a->[0]) cmp lc($b->[0])).
In this script, there are just two owners. So in the script, it was easy
to just compare the names of the owners and sort by that. My problem is
that I need to add a third owner, and this code doesn't lend itself to
being expanded very well. I tried sorting by ($a->[1] eq 'owner1') -
($b->[1] eq 'owner1') for each owner, but I found out that the eq operator
returns a 1 if true and "" if false. I was hoping for a 1 or a 0, but no
such luck.
How can I add a third owner to this?
Thanks
Adam