bodmin has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have an LDIF file containing hundreds of entries however when i run the following code i only get the first printed out. How do i get the complete list?
use Net::LDAP::LDIF; use Net::LDAP::Entry; $ldif = Net::LDAP::LDIF->new( "directory.ldif", "r", onerror => 'warn' + ); while( not $ldif->eof ( ) ) { $entry = $ldif->read_entry ( ); if ( $ldif->error ( ) ) { print "Error msg: ", $ldif->error ( ), "\n"; print "Error lines:\n", $ldif->error_lines ( ), "\n"; } else { print $entry->get_value("sn")."\n"; print $entry->get_value("cn")."\n"; print $entry->get_value("userPassword")."\n"; print $entry->get_value("dn")."\n"; @values = $entry->attributes; print "default: @values\n"; @values = $entry->attributes ( nooptions => 1 ); print "nooptions: @values\n"; } }
LDIF FILE:
dn: cn=Login Server (portal30_sso) cn: Login Server (portal30_sso) description: Central Authentication Authority objectClass: top objectClass: applicationProcess dn: cn=PORTAL30_SSO, cn=Login Server (portal30_sso) sn: PORTAL30_SSO cn: PORTAL30_SSO userPassword: portal30_sso objectClass: top objectClass: person dn: cn=PORTAL30_SSO_ADMIN, cn=Login Server (portal30_sso) sn: PORTAL30_SSO_ADMIN cn: PORTAL30_SSO_ADMIN userPassword: portal30_sso_admin objectClass: top objectClass: person dn: cn=PORTAL30, cn=Login Server (portal30_sso) sn: PORTAL30 cn: PORTAL30 userPassword: portal30 objectClass: top objectClass: person dn: cn=PORTAL30_ADMIN, cn=Login Server (portal30_sso) sn: PORTAL30_ADMIN cn: PORTAL30_ADMIN userPassword: portal30_admin objectClass: top objectClass: person dn: cn=PUBLIC, cn=Login Server (portal30_sso) sn: PUBLIC cn: PUBLIC userPassword: public objectClass: top objectClass: person

Replies are listed 'Best First'.
Re: Read LDIF file
by meetraz (Hermit) on Jun 16, 2004 at 16:29 UTC
    It seems to work fine for me. When I run your example, it produces this output:

    Login Server (portal30_sso) default: cn description objectclass nooptions: cn description objectclass PORTAL30_SSO PORTAL30_SSO portal30_sso default: sn cn userpassword objectclass nooptions: sn cn userpassword objectclass PORTAL30_SSO_ADMIN PORTAL30_SSO_ADMIN portal30_sso_admin default: sn cn userpassword objectclass nooptions: sn cn userpassword objectclass PORTAL30 PORTAL30 portal30 default: sn cn userpassword objectclass nooptions: sn cn userpassword objectclass PORTAL30_ADMIN PORTAL30_ADMIN portal30_admin default: sn cn userpassword objectclass nooptions: sn cn userpassword objectclass PUBLIC PUBLIC public default: sn cn userpassword objectclass nooptions: sn cn userpassword objectclass
      so so strange, and so so annoying! I just get the first block out!