For Programmers: Free Programming Magazines  


Home > Archive > LDAP > May 2006 > Variable wierdness in LDAP search









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Variable wierdness in LDAP search
Erich Weiler

2006-05-07, 7:33 pm

Hi ya'll,

I was hoping someone could shed some light on this problem I'm having
with Net::LDAP. I'm trying to write a bit of perl code that does an
LDAP search and returns, via STDOUT, the value of an attribute in the
LDAP database. In this case, I want the value of "nisMapEntry" from
within "cn=staff". Here is the code I wrote so far, which works:

use Net::LDAP;

my $ldap = Net::LDAP->new('ldap://ldapserver.mydomain.com/') or die "$@";

$ldap->bind;
#chomp $ARGV[0];

my $mount = $ldap->search(base => 'nisMapName=auto.home,dc=mydomain,dc=com',
filter => 'cn=staff');

$mount->code && die $mount->error;

foreach $entry ($mount->all_entries) {
my $subloc = $entry->get_value('nisMapEntry');
print "$subloc\n";
}

$ldap->unbind;

-----

What I CAN'T seem to do is replace 'cn=staff' with a variable, like
'cn=$ARGV[0]'. When I do that the search doesn't work. Maybe it's
actually searching for the string '$ARGV[0]' instead of actually
inserting the value of the variable there? Can anyone help me figure
this out?

Thanks a million in advance!!

ciao, erich

Chris Ridd

2006-05-07, 7:33 pm

On 6/5/06 5:39, Erich Weiler <weiler@soe.ucsc.edu> wrote:

> What I CAN'T seem to do is replace 'cn=staff' with a variable, like
> 'cn=$ARGV[0]'. When I do that the search doesn't work. Maybe it's
> actually searching for the string '$ARGV[0]' instead of actually
> inserting the value of the variable there? Can anyone help me figure
> this out?


This is basic perl :-) Just write the filter value in double-quotes to get
any variables included in the value ("interpolated", in perl lingo):

filter => "cn=$ARGV[0]"

Cheers,

Chris


Erich Weiler

2006-05-07, 7:33 pm

Good lord I'm embarrassed. I've been looking at this thing for hours
and didn't notice the single quotes. Thanks for pointing that out!
(even though it had nothing to to with the Net::LDAP module itself!) :)

ciao, erich

Chris Ridd wrote:
> On 6/5/06 5:39, Erich Weiler <weiler@soe.ucsc.edu> wrote:
>
>
> This is basic perl :-) Just write the filter value in double-quotes to get
> any variables included in the value ("interpolated", in perl lingo):
>
> filter => "cn=$ARGV[0]"
>
> Cheers,
>
> Chris
>


--
===================================
Erich Weiler
UNIX Systems Administrator
School of Engineering
University of California Santa Cruz
weiler@soe.ucsc.edu
===================================
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com