Beast wrote:
Hi,

I have some rather big chunk of data, returned from ldap server. The format is simple:
"Displa name" <[EMAIL PROTECTED]>

Simply displying data "as is" is simple, but how do I sorted by "display name"? pls note that "display name" contains space and might not unique so I can't put it on %hash.
many thanks.



Many thanks to all who helps, it worked now.

----
my $ldap = Net::LDAP->new($ldap_host) or die "$@";
my $mesg = $ldap->bind(version => 3);
$mesg = $ldap->search(  base    => $ldap_base,
                       filter  => "(&(objectclass=mailuser)($dsp_opt))",
                       scope   => "sub",
                       attrs   => ['displayname', 'mail'] );


my $max = $mesg->count;

my @unsorted = ();
my @sorted = ();

for (my $i=0; $i<$max; $i++) {
  my $entry = $mesg->entry($i);
  my $display_name = $entry->get_value('displayname');
  my $mail_address = $entry->get_value('mail');
  push @unsorted, [$display_name, $mail_address];
}

foreach my $cn (sort { lc($a->[0]) cmp lc ($b->[0])} @unsorted) {
  print "\"$cn->[0]\" <$cn->[1]>\n";
}


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