bshah has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I’m novice in Perl. I wrote the below Perl script. I’ve some issue with foreach or while loop and it doesn’t work as expected.
tmp/dl
group1
group2
/tmp/removemem
uid1
uid2
#! /usr/bin/perl -w use Net::LDAP; open ( FH, "<", "/tmp/dls" ) or die "Could not open file... :$! \n"; open ( FH2, "<", "/tmp/removemem" ) or die "Could not open file... :$! + \n"; $ldap = Net::LDAP->new ( “ldap-master" ) or die "$@"; $mesg = $ldap->bind( dn => "uid=admin,ou=SysAccounts,dc=admin +,dc=local", password => “pass", ); while ( $dl = <FH> ) { chomp $dl ; $mesg = $ldap->search ( base => “dc=example, dc=com", filter => "mail=$dl", attrs => [ 'mgrprfc822mailmember' ], ); @entries = $mesg->entries; foreach $entry ( @entries ) { @members = $entry->get_value('mgrprfc822mailmember'); print "\n"; print "$dl\n"; print "Members are: @members\n"; foreach $member ( @members ) { while ( $curmem = <FH2> ) { chomp $curmem; print "\n$curmem\n"; $mesg2 = $ldap->search ( base => “dc=example, dc=com", filter => "uid=$curmem", attrs => [ 'mailLocalAddress' ], ); @entries2 = $mesg2->entries; foreach $entry2 ( @entries2 ) { @current = $entry2->get_value('mailLocalAddress'); print "\n File UID $curmem has following Aliases: @curren +t\n"; # } print "MATCH Starting\n"; if ( grep /^$member$/, @current ) { print "MATCHED: $member\n" ; } # } } } } } } $mesg = $ldap->unbind ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: foreach/while loop help
by Anonymous Monk on Jul 12, 2015 at 23:19 UTC | |
by bshah (Novice) on Jul 12, 2015 at 23:37 UTC | |
by Anonymous Monk on Jul 13, 2015 at 00:36 UTC | |
|
Re: foreach/while loop help
by u65 (Chaplain) on Jul 13, 2015 at 10:37 UTC | |
by bshah (Novice) on Jul 13, 2015 at 22:13 UTC |