Usually, I load parse ldif from file using following method:
use Net::LDAP::LDIF;
use Net::LDAP::Entry;
use Data::Dumper;
my $ldif = Net::LDAP::LDIF->new( "filename.ldif", "r") or die "file not exits\n";
while( not $ldif->eof ( ) ) {
$entry = $ldif->read_entry ( );
print Dumper $entry;
}
but instead of load from file, I need load the LDIF format file directly from variable string. so the code will look like :
use Net::LDAP::LDIF;
use Net::LDAP::Entry;
use Data::Dumper;
my $var_ldif = "dn: cn=Sheri Smith,ou=people,dc=example,dc=com
objectclass: inetOrgPerson
cn: Sheri Smith
sn: smith
uid: ssmith
userpassword: sSmitH
carlicense: HERCAR 125
homephone: 555-111-2225";
my $ldif = Net::LDAP::LDIF->new( $var_ldif, "r") or die "file not exits\n";
while( not $ldif->eof ( ) ) {
$entry = $ldif->read_entry ( );
print Dumper $entry;
}
so, how to do it corectly?
thanks and sorry for this stupid question. :) BR//
BACKGROUND IDEA My goal is to build script that compare LDIF data before and after in detail (from dn until attribute values, one by one). the LDIF data itself is really huge, about 10GB or more per file.
*So I come with idea to read the file per-DN, and compare it before and after. parsing of each DN is stored in $variable_before and $variable_after. that is why I actually need data from $ variable, because the 'LDIF format data' is come from output from previous process. *
I need LDAP::LDIF to make easier to parse LDIF string into perl hashref.
I avoid using temporary file because the "DN data" is really much, will slower in processing if using temporary file.
You can append the data you have to the end of the script and read from the DATA filehandle ( Net::LDAP::LDIF documentation states the first parameter can be a filename or a filehandle )
Another solution is to write the contents of the $var_ldif to a temporary file.
Are you sure NET::LDAP::LDIF is the right module for what you want to do ?