LDAP sorting

View: New views
2 Messages — Rating Filter:   Alert me  

LDAP sorting

by ahappydeath :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Anyone have any idea how to make the '$result->sorted' method of
Net::LDAP become case insensitve?

Re: LDAP sorting

by Leon Timmermans :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 04 Jun 2008 08:18:40 -0700, ahappydeath wrote:

> Anyone have any idea how to make the '$result->sorted' method of
> Net::LDAP become case insensitve?

Aside from using some really evil magic, I see no way to do that, but I
don't think you need to do that. You can just sort it yourself (it's
sorted on the client side anyway). I haven't tested this, but based on
the Net::LDAP code I'd say it should work something like this.


my $attribute = "some attribute you want to use to sort";
my $msg = $ldap->search(...);

my @sorted_entries =
    map { $_->[0] }
    sort { $a->[1] cmp $b->[1] }
    map { [ $_, lc join("\000", @{ $_->get_value($attribute, asref => 1)
|| [] } ) ]}
    $msg->entries();


It's not the prettiest Schwartzian transform ever, but it should work.

Cheers,

Leon

.
LightInTheBox - Buy quality products at wholesale price!