通常,我使用以下方法从文件中加载解析 ldif:
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;
}
但不是从文件加载,我需要直接从变量 string 加载 LDIF 格式文件。所以代码看起来像:
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;
}
那么,如何正确地做到这一点?
感谢并为这个愚蠢的问题感到抱歉。:) BR//
背景想法 我的目标是构建脚本,详细比较前后的 LDIF 数据(从 dn 到属性值,一一进行)。LDIF 数据本身非常庞大,每个文件大约 10GB 或更多。
*所以我想到了按 DN 读取文件,并在前后进行比较。每个 DN 的解析存储在 $variable_before 和 $variable_after 中。这就是为什么我实际上需要来自 $ 变量的数据,因为“LDIF 格式数据”来自上一个过程的输出。*
我需要 LDAP::LDIF 以便更容易地将 LDIF 字符串解析为 perl hashref。
我避免使用临时文件,因为“DN 数据”非常多,如果使用临时文件,处理速度会变慢。