[ale] perl bogosity

Jeff Jansen bamakojeff at gmail.com
Tue May 24 20:37:31 EDT 2016


Dear Todor,

The '=>' operator (fat comma) IS a comma in perl.  It operates just a like
a comma except that if the left side is a bare word, it is treated as a
string. So (a => 'b') is the same as ('a' , 'b').  It's really just to help
us humans see the relationship between items.

@var = (dayofweek => 'tuesday', month => 'june', day => '24')
is "easier" to read than
@var = ('dayofweek' , 'tuesday', 'month', 'june', 'day', '24')

But they are both equivalent code to create an array.  The first example
just makes it more clear that we are putting pairs of data into the array
in a certain order.  But it's still just an array of six items in a certain
order.

(http://perldoc.perl.org/perlop.html#Comma-Operator)

So all the ldap code all looks perfectly normal to me.  You could replace
all the fat commas with commas if that makes more sense.  But the code is
the same.

$var = ['string1' => 'value'];" is not a syntax error because you are
assigning a scalar variable to an array created with brackets, so perl
creates the array and then creates the scalar variable as a reference to
it. You could also write "$var = ['string1' , 'value'];" and do the exact
same thing.

HTH  I'm not sure I understand what part of the LDAP code doesn't make
sense to you so if this isn't clear let me know exactly what it is that
doesn't make sense to you.

Jeff

PS - this is all for perl5.  Perl6 makes changes to all this.

On Tue, May 24, 2016 at 12:50 PM, Todor Fassl <fassl.tod at gmail.com> wrote:
>
> 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
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20160524/ede2608f/attachment.html>


More information about the Ale mailing list