Re: Multiple hosts in an array reference

Quanah Gibson-Mount <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.ldap
Message-ID <EB33E8C45CEB043CD58EB9E6@[192.168.1.199]>
--On Wednesday, November 26, 2008 2:30 PM -0600 Christopher A Bongaarts 
<[email protected]> wrote:

> In the immortal words of Quanah Gibson-Mount:
>> According to the Net::LDAP documentation:
>>
>> new ( HOST, OPTIONS )
>>
>> HOST may also be a reference to an array of hosts, host-port pairs or
>> URIs  to try. Each will be tried in order until a connection is made.
>> Only when  all have failed will the result of undef be returned.
> [...]
>>  $ldap_url = \@ldap_url;
>>  print "LDAP URL is now $ldap_url\n";
>>  $ldap=Net::LDAP->new("$ldap_url");
>
> Should be checking that $ldap is defined here to avoid the error ;)

Yeah, but first I want things to just work. :P

>> LDAP URL is now ARRAY(0x1a3752c0)
>
> And since you're passing an array referenced *interpolated into a
> string*, this will fail unless your LDAP server's hostname happens to
> be "ARRAY(0x1a3752c0)".

<http://www.perl.com/doc/manual/html/pod/perlref.html>

References can be created in several ways.

   1. .

      By using the backslash operator on a variable, subroutine, or value. 
(This works much like the & (address-of) operator in C.) Note that this 
typically creates ANOTHER reference to a variable, because there's already 
a reference to the variable in the symbol table. But the symbol table 
reference might go away, and you'll still have the reference that the 
backslash returned. Here are some examples:

          $scalarref = \$foo;
          $arrayref  = \@ARGV;
          $hashref   = \%ENV;
          $coderef   = \&handler;
          $globref   = \*foo;

I submit it is a reference to an array, at least according to the 
documentation from the Perl website.

In any case, if I change the code to be a pure reference, I still get the 
same problem:

  $ldap=Net::LDAP->new("\@ldap_url");

>> Now, if I switch back to just a single URI, things work just fine:
>>
>> LDAP URL is ldap://freelancer.lab.zimbra.com:389
>
> Why this prints a string instead of the ARRAY(xxx) I can't figure out.

Because I commented the array bits out and just left it a plain string on a 
single value. ;)

--Quanah

--

Quanah Gibson-Mount
Principal Software Engineer
Zimbra, Inc
--------------------
Zimbra ::  the leader in open source messaging and collaboration
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.