[Omaha.pm] Learning perl - working with LDAP
bbrush at gmail.com
Fri Feb 24 08:36:00 PST 2012
Hello everyone. I just recently started down the path of learning
Perl, and I'm working on my first script (program? which is the
correct term for Perl?).
Anyway, I'm basing it on the example here:
Getting down to the details of the code, I want to throw out some
lines and how I interpret them to make sure I'm reading them right.
This line seems to be the money line of the example:
my $results = $ad->search(base=>$base,filter=>$filter,attrs=>$attrs);
The way I read that is:
my $results = (the output of this command will be stored in $results)
$ad->search (Use the search method in the previously created object $ad)
(base=>$base,filter=>$filter,attrs=>$attrs) (The search method has 3
inputs required [base,filter, attrs] which are stored in the 3
variables. Base corresponds to the LDAP context where the search will
be performed, filter gives the criteria of the objects selected, and
attrs gives the attributes to be returned. Presumably these could
have been written out explicitly rather than stored in variables, but
this is infinitely more readable and flexible.)
So am I reading that command correctly?
Another question about the example script is minor, but I haven't
found the answer elsewhere. The author uses the operator .= (dot
equal). What does that do?
A final question is more of a code style and efficiency question. The
author uses a FOR-NEXT loop to cycle through the alphabet. Wouldn't a
While (letter<z) or Until (letter =z) loop structure be more concise?
I'm trying to understand if there's an advantage to the author's
method that I'm not grasping.
More information about the Omaha-pm