in reply to Re^5: Perl Builds an LDIF
in thread Perl Builds an LDIF
Humbled, I return for wisdom. The while statements are erratic, my wish is to have a 1to1 relationship between the while statements and the input files, yet the 2nd while <MGR> will pull results for 50 lines before the first while <PERSON> runs again. I wish to read iteratively <PERSON> one line at a time, then print @lines, then read iteratively <MGR>, one line at a time, resulting in a four lines written to OUT or buildAD.ldif.
Also, perl throws an error on the second $_ use; how else may it be defined as I wish to place the next line from <MGR> file into the filter?
Error reads: Use of uninitialized value $_ in pattern match (m//) at build4.pl line 48, <MGR> line 120 (#1)(W uninitialized) An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a mistake. To suppress this warning assign a defined value to your variables.
I am also puzzled why print OUT (@lines) does not print the contents of LDIFA after each line of <PERSON> is processed (instead it is printing erratically to OUT). And, why OUT fails in Net::LDAP::LDIF->new( "OUT", "a", wrap=>40 );, I am forced to hardcode "buildAD.ldif" instead of OUT.
my $ldap = Net::LDAP->new("$HOST", port=>389) or die "$@"; my $dn = $ldap->bind("$ADMIN", password=>"$PWD"); my $dnm = $ldap->bind("$ADMIN", password=>"$PWD"); my @attr = "1.1"; my $result = Net::LDAP::LDIF->new( "buildAD.ldif", "a", wrap=>40 ); my @lines = (<LDIFA>); while (<PERSON>) { chomp; $dn = $ldap->search( #return only the employeeID DN base => "$BASEDN", filter => "(&(objectClass=user)(employeeID=$_))", scope => "sub", attrs => [@attr] ); next unless $dn; # Make sure something is returned while( my $entry = $dn->pop_entry() ) { $result->write_entry($entry); if ( $result != /dn:/ ) { print OUT (@lines); } while (<MGR>) { chomp; $dnm = $ldap->search( #return only the manager DN base => "$BASEDN", filter => "(&(objectClass=user)(employeeID=$_))", scope => "sub", attrs => [@attr] ); next unless $dnm; # Make sure something is returned while( my $entry = $dnm->pop_entry() ) { $result->write_entry($entry); } } } } $dn = $ldap->unbind; #session ends $dnm = $ldap->unbind; #session ends close OUT2 or die "Cannot close in-memory file: $!"; close OUT or die "Cannot close in-memory file: $!"; close MGR or die "Cannot close in-memory file: $!"; close PERSON or die "Cannot close in-memory file: $!"; close LDIFA or die "Cannot close in-memory file: $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Perl Builds an LDIF
by Corion (Patriarch) on Jun 16, 2010 at 20:37 UTC | |
|
Re^7: Perl Builds an LDIF
by NetWallah (Canon) on Jun 16, 2010 at 22:22 UTC | |
by rfransix (Novice) on Jun 17, 2010 at 20:01 UTC | |
by rfransix (Novice) on Jun 17, 2010 at 20:15 UTC | |
by NetWallah (Canon) on Jun 18, 2010 at 00:56 UTC | |
by rfransix (Novice) on Jun 21, 2010 at 21:42 UTC | |
by NetWallah (Canon) on Jun 23, 2010 at 04:52 UTC | |
|