[aklug] Re: slightly OT: Perl Net::LDAP

From: Royce Williams <royce@tycho.org>
Date: Tue May 24 2016 - 07:45:35 AKDT

On Tue, May 24, 2016 at 7:37 AM, Todor Fassl <fassl.tod@gmail.com> wrote:
>
> On 05/20/2016 01:10 PM, Royce Williams wrote:
>>
>> On Fri, May 20, 2016 at 9:49 AM, Todor Fassl <fassl.tod@gmail.com> wrote:
>>>
>>> Essentially, my question is, in perl, what is the difference between
>>> saying:
>>>
>>> $array = ['one' => 1, 'two' => 2];
>>>
>>> and
>>>
>>> $array = {'one' => 1, 'two' => 2};
>>>
>>> I am trying to write an ldap add function in perl. Something in the
>>> documentation puzzles me:
>>> http://search.cpan.org/~gbarr/perl-ldap-0.33/lib/Net/LDAP.pod
>>>
>>> That page shows the second parameter to the add function being a anonymous
>>> array ref created by using brackets, '[ ... ]'.
>>>
>>> But then it appears to use string keys. Doesn't that make it a hash or an
>>> associative array? Therefore, shouldn't it be instantiated with braces, "{
>>> ... }"?
>>>
>>> --
>>> Tod
>>
>>
>> Braces mean a hash reference.
>>
>> http://stackoverflow.com/a/11839874
>
>
> Dude, isn't it obvious from my question that I know that braces mean a hash reference?

No. Your original message began with what appeared to be a summary of
your question that seemed to indicate that you did not. I deal with
high volumes of email, and I answered as best as I could with the
information that I had absorbed -- admittedly, by reading too quickly,
but nevertheless in good faith.

Also, please drop the "dude, isn't it obvious". We try to be more
polite than this in this forum. It's not the way to treat people who
are trying to help you.

> My question is how can the Net::LDAP module use brackets to instantiate a normal array reference and then, apparently, use it as a hash reference? I wrote some code to check the validity of my question:
>
> #!/usr/bin/perl
> use Data::Dumper;
> $junk = {'apple' => 1, 'banana' => 6, 'cherry' => 99};
> print "TYPE=" . ref($junk) . "\n" . Dumper ($junk);
>
> As expected, this gives the following output:
>
> TYPE=HASH
> $VAR1 = {
> 'banana' => 6,
> 'cherry' => 99,
> 'apple' => 1
> };
>
> So far so good. Same code except the braces for the hash reference are changed to brackets:
>
> #!/usr/bin/perl
> use Data::Dumper;
> $junk = ['apple' => 1, 'banana' => 6, 'cherry' => 99];
> print "TYPE=" . ref($junk) . "\n" . Dumper ($junk);
>
> This displays the following:
>
> TYPE=ARRAY
> $VAR1 = [
> 'apple',
> 1,
> 'banana',
> 6,
> 'cherry',
> 99
> ];
>
> I suspect that in perl, if you treat a normal array reference as a hash reference, it just deals with it. But that seems really sloppy. I can't be messing around with my ldap database.

I don't have the combo of cycles and competence to delve into this one
-- maybe someone else can field it.

Royce
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Tue May 24 07:46:29 2016

This archive was generated by hypermail 2.1.8 : Tue May 24 2016 - 07:46:29 AKDT