[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Omaha.pm] Learning perl - working with LDAP
On Fri, Feb 24, 2012 at 10:36 AM, Bill Brush <bbrush@gmail.com> wrote:
> I'm working on my first script (program? which is the correct term for Perl?)
I say "script" for tiny things and "program" for more serious things. Some people spend lots of energy arguing this topic. I don't recommend you spend any energy caring about it. :)
On Feb 24, 2012, at 11:19 AM, Theodore Katseres wrote:
> use Modern::Perl;
Theodore++ I'm still doing what that does manually. I have no good reason to do so. :)
> for my $letter ( a .. z ) {
> # Filter on the staff membership and
> # first letter of samaccountname attribute
> my $filter = "(&(memberof=CN=staff,OU=groups,DC=ad,DC=wjgilmore,DC=com)(samaccountname=$letter*))";
Code looks good to me if you want to make 26 LDAP queries. If 1 LDAP query would be better for some reason you could pull everything into memory and write each letter to disk later.
Note a..z isn't gonna work worth a damn if you have any Japanese employees. My good friend 愛子 will feel very left out of your directory. :)
> open( FILE, '>', "/www/wjgilmore/directory/$letter.html" );
> say FILE $toc, $directory;
> close FILE;
I believe the preferred modern form of this is:
my $filename = "/www/wjgilmore/directory/$letter.html";
open my $fh, '>', $filename or die "Can't write to '$filename'";
say $fh $toc, $directory;
close $fh;
http://www.modernperlbooks.com/mt/2011/07/why-the-modern-perl-book-avoids-bareword-filehandles.html
?
Hope that helps,
j