【问题标题】:Perl Script LDAP search returns Hash but $mesg->entry returns nothingPerl 脚本 LDAP 搜索返回 Hash 但 $mesg->entry 不返回任何内容
【发布时间】:2013-05-02 00:52:05
【问题描述】:

这是我在 StackOverFlow 上的第一个问题,如果我做错了什么,请告诉我。

这是我的脚本:

#!/usr/bin/perl
use Net::LDAP;
use warnings;
use strict;
my($user,$ldap,$mesg,$info,$entry,$x,$y);
$user = $ARGV[0];
$ldap = Net::LDAP->new ("dirproxy.paychex.com") or die "$@";
$mesg = $ldap->search(filter=>"(uid=$user)", base=>"ou=people,o=paychex inc,c=us");
print $mesg; #hash of entry
$info = "$user,,";
$x=$y=' ';
foreach $entry ($mesg->entry)
{
    print "hello?";
    if(length $entry->get_value("payxlocation")) #if > 0
    {
        $x = $entry->get_value("payxlocation");
        $x =~ s/,//g;
    }

    if(length $entry->get_value("organization")) #if > 0
    {
        $y = $entry->get_value("organization");
        $y =~ s/,//g;
    }

    $info = "$user,$x,$y";
}
print $info;

打印 $info 打印“用户,”。问题似乎出在我的 foreach 语句中

foreach $entry ($mesg->entry)

"$mesg->entry" 是空的,因此它会跳过 foreach 并打印用户,而无需其他信息。

【问题讨论】:

    标签: perl ldap


    【解决方案1】:
    foreach $entry ($mesg->entry)
    

    应该是:

    foreach $entry ($mesg->entries)
    

    更多关于Net::LDAP::Search的信息,在这里你可以看到entryentries之间的区别

    【讨论】:

    • 感谢您的回复。不幸的是,这会导致同样的事情。即什么都没有。我都试过了……
    • 在这种情况下,请修改您的搜索过滤器
    • 这个脚本也工作了 2 个月。相同的脚本。另一个脚本现在被破坏了......真的没有意义。
    • LDAP 服务器有什么变化?
    猜你喜欢
    • 1970-01-01
    • 2011-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 2020-04-15
    • 2021-11-20
    相关资源
    最近更新 更多