Re: Net::LDAP compare question



Ok, I added "use strict;" and found some defects. I am still not
getting the expected results though. This is where it should do the
compare:

my $href = $result->as_struct;

my @arrayOfDNs = keys %$href;


my $dn;
my $res;
my @entries;
my $entr;
my $mesg;
my $crap;

foreach ( @arrayOfDNs ) {
$dn = $_;
$res = $ldap->compare ( $dn,
attr => "$attrs",
value => ''
);
@entries = $res->dn;

foreach $entr ( @entries ) {
$crap = $entr->dn;
print $crap, "\n";


I think I am doing something wrong as far as the compare statement.
This should take the attribute list that I defined earlier in the
script, and return a value of true or false based on the value. If
true, print the DN for the entry. If false, go to the next entry. For
some reason this isn't happening and I don't see the reason why.

Good idea about using strict though.


James E Keenan wrote:
max_headroom27606@xxxxxxxxx wrote:
I am writing a perl script to query an ldap database and find users who
do not belong to any mail distribution list. I can run the query just
fine, but my problem is getting only results back for users who do have
an attribute entry for the field "memberOf". Here is my code
listing....


I'm not very familiar with Net::LDAP and, in any case, I don't have
access to an LDAP right now on which to test. But I think you should
rule out the possibility that you're getting problems by writing less
than optimal Perl code.

use strict; # this will require you to declare all variables with 'my'
use warnings;

$ldap = Net::LDAP->new( '**************' );

$mesg = $ldap->bind ( "$user",

# unnecessary stringification: $user will suffice; drop the quotes
# for this and all other instances

password => "$password",
version => 3 );

if (!$base) { $base = "ou=****,ou=*****,dc=******,dc=******"; }

if (!$attrs) { $attrs = [ 'memberOf' ]; }

$search = 'mail=*@**********.com';

$result = $ldap->search ( base => "$base",
scope => "sub",
filter => "$search",
attrs => $attrs
);


$href = $result->as_struct;

@arrayOfDNs = keys %$href;

foreach ( @arrayOfDNs ) {
$dn = $_;

# Above 2 lines could be reduced to:

foreach my $dn (@arrayOfDNs) {

$res = $ldap->compare ( $dn,
attr => "$attrs",
value => ''
);
@entries = $res->dn;


# Without thinking too hard about it, what does '->dn' mean in the above
line: method call? hash dereference?

foreach $entr ( @enties ) {
$butes = $entr->dn;
print $butes, "\n";
}

print "#-------------------------------\n";
}

$mesg = $ldap->unbind;



This is pretty much a cut/paste of the example given in CPAN,

That will only be true once you've coded it more cleanly and rerun it
with strictures and warnings.

jimk

.



Relevant Pages

  • Re: Appending a character to a field
    ... use strict; ... close DFOUT; ... it's to truncate the percent sign % from the df -k output, compare the ...
    (perl.beginners)
  • Re: List to hash/dict?
    ... and passes their second components to compare. ... In the second version the comparator passes to compare two expressions ... are usually strict by their nature. ... But if this call site is polymorphic, the compiler can't a priori ...
    (comp.lang.functional)
  • Re: Checking on logical functionality
    ... The content of file1 is A&B while file 2 ... How can I compare and print that the functionality is same. ... use strict; use warnings; ... sub A ...
    (perl.beginners)
  • Re: SAT question
    ... jennifer wrote: ... Indeed that makes C less than A+B, but if you compare ... In a nondegenerate triangle, the strict ... inequality has to hold for all three sides. ...
    (sci.math)
  • Re: Net::LDAP compare question
    ... use strict; # this will require you to declare all variables with 'my' ... attrs => $attrs ... foreach my $dn (@arrayOfDNs) { ... That will only be true once you've coded it more cleanly and rerun it with strictures and warnings. ...
    (comp.lang.perl.modules)