[ale] perl bogosity

Todor Fassl fassl.tod at gmail.com
Tue May 24 12:50:52 EDT 2016


Quoting from the documentation for the Net::LDAP module at
http://search.cpan.org/~marschap/perl-ldap/lib/Net/LDAP.pod

  $result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan, c=US',
                        attrs => [
                          'cn'   => ['Barbara Jensen', 'Barbs Jensen'],
                          'sn'   => 'Jensen',
                          'mail' => 'b.jensen at umich.edu',
                          'objectclass' => ['top', 'person',
                                            'organizationalPerson',
                                            'inetOrgPerson' ],
                        ]
                      );


Note that the second parameter is a hash reference. However, the attrs 
element is set to an array reference with string keys.  Not a hash ref, 
mind you, a normal array ref. I found tons of sample code out there with 
the same syntax.

I also wrote a test program.

#!/usr/bin/perl
use Data::Dumper;
$junk = ['apple' => 1, 'banana' => 6, 'cherry' => 99];
print "TYPE=" . ref($junk) . "\n" . Dumper ($junk);

That code gives the following output:

TYPE=ARRAY
$VAR1 = [
           'apple',
           1,
           'banana',
           6,
           'cherry',
           99
         ];


So the arrows (=>) are treated like commas. It does not create a hash 
ref. I would think the Net::LDAP documentation is just wrong except that 
I've seen dozens of other pages with sample code that says the same thing.

PS: IMO, "$var = ['string1' => 'value'];" should be a syntax error.



-- 


Todd


More information about the Ale mailing list