Re: My first perl program after 6 years (need help on Win32::OLE ADSI script)
Hi Andrew, On Thu, Sep 6, 2012 at 5:23 AM, andrew sison andrew.sison...@gmail.com wrote: I've done some reading and learned that in order to automate that particular task using perl, I would have to use either Win32::OLE or Net::LDAP. So I decided to use to former. Actually, I would strongly recommend using Net::LDAP. It is specialized in LDAP searches plus it comes with a bunch of helpful scripts and examples, check the bin/ and contrib/ folders. See here: https://metacpan.org/source/MARSCHAP/perl-ldap-0.46 -- Mike -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: My first perl program after 6 years (need help on Win32::OLE ADSI script)
Hi Andrew, I'm not an OLE or Win32::OLE expert, but see below for a review of your code: On Thu, 6 Sep 2012 11:23:41 +0800 andrew sison andrew.sison...@gmail.com wrote: Hello, It has been six years since I have shifted into a new role from being a systems administrator to being an IT auditor. It's been a while since I've written my last perl script. Now I'm back here again to get some help. Basically my job now requires me to conduct audits on the information stored in our active directory. I've done some reading and learned that in order to automate that particular task using perl, I would have to use either Win32::OLE or Net::LDAP. So I decided to use to former. Now I am confronted with this simple problem which one would consider the biggest hurdle that a beginner programmer has to overcome for the first time. This is like the hello world program for me. If I can get past this, I know I can do anything. The problem with the code below is that it is not able to retrieve the object if I type in my DN. If it's just the container OUs, then it seems to work fine. Let's say I would put OU=CODP,OU=Users,OU=MLAPH,OU=AsiaPacific,OU=MLAROOT,DC=int,DC=mlaph,DC=com instead, it would work just fine. It doesn't work when I specify a user's distinguished name. Unfortunately for me, I'm still looking for reference materials to help me with ADSI/COM programming in perl because the documentation for Win32::OLE doesn't really say much to help me going. Is there anything here you can recommend? #!/usr/bin/perl use 5.010; use strict; use warnings; These pragmas are good. Thanks for being clueful. use Win32::OLE; my $userObject = Win32::OLE-GetObject(LDAP://CN=Sison\, Andrew,OU=CODP,OU=Users,OU=MLAPH,OU=AsiaPacific,OU=MLAROOT,DC=int,DC=mlaph,DC=com) or die Unable to retrieve object, \n; OK, «\,» inside a double-quoted string is equivalent to a simple comma («,»), so why is it there? Are you trying to have a multi-line string? If so use \n inside the string, and maybe http://perldoc.perl.org/functions/join.html to split it into several shorter components. But, as it stands now, your string will have a comma and a newline. Second piece of advice is that «die Unable to retrieve object, \n» should be written as «die Unable to retrieve object\n» assuming you want to have the trailing newline. I'm not sure if the die command accepts a list. print $userObject-{displayName}, \n; It's strange that Win32::OLE allows you to access object slots directly like that, but maybe it was before accessors were as commonly accepted as they are today. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ List of Text Editors and IDEs - http://shlom.in/IDEs Better be a tail for the lions, than the head of the jackals. — Pirkei Avot, 4 15 Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
My first perl program after 6 years (need help on Win32::OLE ADSI script)
Hello, It has been six years since I have shifted into a new role from being a systems administrator to being an IT auditor. It's been a while since I've written my last perl script. Now I'm back here again to get some help. Basically my job now requires me to conduct audits on the information stored in our active directory. I've done some reading and learned that in order to automate that particular task using perl, I would have to use either Win32::OLE or Net::LDAP. So I decided to use to former. Now I am confronted with this simple problem which one would consider the biggest hurdle that a beginner programmer has to overcome for the first time. This is like the hello world program for me. If I can get past this, I know I can do anything. The problem with the code below is that it is not able to retrieve the object if I type in my DN. If it's just the container OUs, then it seems to work fine. Let's say I would put OU=CODP,OU=Users,OU=MLAPH,OU=AsiaPacific,OU=MLAROOT,DC=int,DC=mlaph,DC=com instead, it would work just fine. It doesn't work when I specify a user's distinguished name. Unfortunately for me, I'm still looking for reference materials to help me with ADSI/COM programming in perl because the documentation for Win32::OLE doesn't really say much to help me going. Is there anything here you can recommend? #!/usr/bin/perl use 5.010; use strict; use warnings; use Win32::OLE; my $userObject = Win32::OLE-GetObject(LDAP://CN=Sison\, Andrew,OU=CODP,OU=Users,OU=MLAPH,OU=AsiaPacific,OU=MLAROOT,DC=int,DC=mlaph,DC=com) or die Unable to retrieve object, \n; print $userObject-{displayName}, \n; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
First perl program
I'm really new to programming and this is my first perl prog. I'm looking for any advice or comments on this script. (I don't want to develop bad habits from the start) Thx. #!/usr/bin/perl #Name:circumf #Date:Jun19/08 #Author:Bornhoft, J #Purpose:to calculate the circumference of a circle print Hi. I'm going to help you calculate the circumference of a circle\n; $pi = 3.141592654; print What is the radius of the circle?: ; chomp($radius = STDIN); if ($radius 0) { $radius = 0; print Psst...\nThe radius can\'t be less than zero.\nLet me help you out there\n; } $diameter = ($radius * 2); $area = ($pi * ($radius ** 2)); $circumf = ($diameter * $pi); print Radius: $radius\n Diameter: $diameter\n Area: $area\n And finally!!!\n Circumference: $circumf\n;
Re: First perl program
Hi Jason, To start with you are going to get quite a few replies that will tell you to use strict and enable warnings because that is what good perl programers do. :-) #!/usr/bin/perl use strict; use warnings; #Name:circumf Strict basically forces you to scope your variables, there is a lot of information about this in all kinds of tutorials so I am not going to repeat it all here or pretend that I would even be able to do so. At least for starters it is enough to know that you can put my infront of every new variable that you want to use to decalre it as in use and that this variable will only be available in the subroutine that you have declared it in (basically the variable declared before a { is not available after the { which is the simplest way to put it for a beginner in my humble opinion). Warnings are much simpler as the name says it enables warnings in perl, and you will be informed of potential incorrect ways of writting code, like and array element being addressed as @array[2] will cause perl to write a warning to STDERR complaining that you should have used $array[2] instead. Other then that you might want to have a little less trust in your users, and verify that what they put in is actually a number and not a bit of text or something like that, but as you say this is just a program to start to learn so it might be a bit overkill to check your own input. Regards, Rob Coops On Thu, Jun 19, 2008 at 8:55 AM, Jason B [EMAIL PROTECTED] wrote: I'm really new to programming and this is my first perl prog. I'm looking for any advice or comments on this script. (I don't want to develop bad habits from the start) Thx. #!/usr/bin/perl #Name:circumf #Date:Jun19/08 #Author:Bornhoft, J #Purpose:to calculate the circumference of a circle print Hi. I'm going to help you calculate the circumference of a circle\n; $pi = 3.141592654; print What is the radius of the circle?: ; chomp($radius = STDIN); if ($radius 0) { $radius = 0; print Psst...\nThe radius can\'t be less than zero.\nLet me help you out there\n; } $diameter = ($radius * 2); $area = ($pi * ($radius ** 2)); $circumf = ($diameter * $pi); print Radius: $radius\n Diameter: $diameter\n Area: $area\n And finally!!!\n Circumference: $circumf\n;
Re: First perl program
Jason B schreef: #!/usr/bin/perl Missing: use strict; use warnings; #Name:circumf #Date:Jun19/08 #Author:Bornhoft, J #Purpose:to calculate the circumference of a circle print Hi. I'm going to help you calculate the circumference of a circle\n; Alternative: print 'EOT'; Hi. I'm going to help you calculate the circumference of a circle EOT $pi = 3.141592654; my $pi = atan2(0, -1); print What is the radius of the circle?: ; chomp($radius = STDIN); if ($radius 0) { $radius = 0; print Psst...\nThe radius can\'t be less than zero.\nLet me help you out there\n; print 'EOT'; Psst... The radius can't be less than zero. Let me help you out there EOT } $diameter = ($radius * 2); $area = ($pi * ($radius ** 2)); $circumf = ($diameter * $pi); Really no need for all those patrentheses. my $diameter = $radius * 2; my $area = $pi * $radius ** 2; my $circumf = $diameter * $pi; print Radius: $radius\n Diameter: $diameter\n Area: $area\n And finally!!!\n Circumference: $circumf\n; print EOT \tRadius : $radius \tDiameter : $diameter \tArea : $area And finally!!! \tCircumference: $circumf EOT __END__ -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: First perl program
Hi, Jason B [EMAIL PROTECTED] wrote: I'm really new to programming and this is my first perl prog. I'm looking for any advice or comments on this script. Enable warnings and use strict;. That'll help you to write better code. #!/usr/bin/perl #!/usr/bin/perl -w use strict; #Name:circumf #Date:Jun19/08 #Author:Bornhoft, J #Purpose:to calculate the circumference of a circle print Hi. I'm going to help you calculate the circumference of a circle\n; $pi = 3.141592654; my $pi = 3.141592654; With warnings enabled (perl -w or use warnings) you have to declare your variables using my on or before first use. The benefit is that this will help you to identify mistyped variable names and thus bugs in your code. HTH, Thomas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: First perl program
Thomas Bätzler schreef: #!/usr/bin/perl -w Read perllexwarn. -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/