Hi Mick,

Besides me recommending that you use strict I notice that in your main loop you have a completely unnecessary flip flop from individual scalars to 1 scalar and back again (join then split on lines 15 && 16)

It also that there are better methods to use in the wonders that are Net::LDAP (like entries to avoid the $max stuff). Are you using the most recent version? This is the documentation I'm using. Unfortunately I don't have an LDAP server to test against so the best test I can do is a perl -c which I can't do because ppm can't find the ppd from Activestate (grr windows).

Here's my shot:

use Net::LDAP; use strict; my $id ='1234'; my $ldap = Net::LDAP->new('host','port') or die "$@"; $ldap->bind; my $mesg = $ldap->search (base => $base, filter => "employee_number=$id", attrs => [firstname,lastname,employee_number,department,ci +ty]); my %userinfo; foreach my $entry ($mesg->entries){ foreach my $attr ($entry->attributes){ $userinfo{$attr} = $entry->get($attr); } #$entry->dump; # saw it in the examples but no docs! } # test the hash... foreach my $attr (keys %userinfo){ print "$attr\t$userinfo{$attr}\n"; } $ldap->unbind;

I saw where in the documentation you got your example but I think this works a little more efficiently (if it works at all)

Sorry about the lack of testing, normally I wouldn't do this (post untested code).

--
Clayton
Long time reader, first time poster.


In reply to Re: Is there a better solution: data from Net::LDAP? by clscott
in thread Is there a better solution: data from Net::LDAP? by mrmick

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.