How to use get_value to get objectName?
This code
my @bl = ();
foreach my $entry ($m->entries) {
push @bl, "$entry->get_value('objectName', asref => 0)";
}
print Dumper @bl;
outputs
$VAR1 = 'Net::LDAP::Entry=HASH(0x5c70920)->get_value(\'objectName\', asref => 0)';
$VAR1 = 'Net::LDAP::Entry=HASH(0x5c706c0)->get_value(\'objectName\', asref => 0)';
$VAR1 = 'Net::LDAP::Entry=HASH(0x5c70660)->get_value(\'objectName\', asref => 0)';
which I don't understand why it does.
If I change objectName
to sAMAccountName
, it gives something m开发者_如何学Pythoneaningful.
If I dump $m->entries
I see
$VAR1 = bless( {
'changes' => [],
'changetype' => 'modify',
'asn' => {
'objectName' => 'CN=sandra,OU=list,DC=example,DC=com',
'attributes' => []
}
}, 'Net::LDAP::Entry' );
How do I get the objectName
using get_value()
?
Update: First comment solved the problem.
Method calls are not interpolated into double-quoted strings. In this case, it doesn't seem like you need the quotes at all:
my @bl = ();
foreach my $entry ($m->entries) {
push @bl, $entry->get_value('objectName', asref => 0);
}
Or, better yet:
my @bl = map { $_->get_value('objectName', asref => 0) } $m->entries;
Note that Ibrahim's comment is a bad idea. You should never go poking around inside an object's internals; use the public interface instead.
FYI objectName
here is the object's DN. To get/set it you should be using $entry->dn
精彩评论