Converting VBScript examples to Perl is actually pretty easy.  There are
some examples in the documentation for Win32::OLE.

Here are some of the basics:

1.  All objects are scalars, even collections.  If you need to expand a
collection into an array, use the in() function from Win32::OLE, like
this:

        use Win32::OLE qw(in);
        my $collection = something;

        foreach my $obj(in($collection)){
           print $obj->{Name}."\n";
        }

2.  Methods and properties are invoked using the -> operator

        use Win32::OLE qw(in);
        my $obj = Win32::OLE->GetObject("SomeObject");
        my $objectName = $obj->{Name};
        my $altName = $obj->GetAlternateName();


3.  Some functions use a long integer time format that is difficult to
deal with.  (the lastLogon property of users in AD, for example)  I
created this function to translate it into perl time() format from
scraps I found on the Internet:

        sub MS2PerlTime {
           my $uPval = pack( "II", $_[0]->{LowPart}, $_[0]->{HighPart}
);
           my ( $bVp, $aVp ) = unpack( "LL", $uPval );
           $uPval = ( $aVp * 2**32 + $bVp ) / 10000000;
           return ( $uPval - 11644473600 );    #convert to Perl time
        }

4.  To mimic the "On Error Resume Next" functionality, set the following
line near the top of your script.  Otherwise any error will kill your
script.

        Win32::OLE->Warn(0);

5.  Download the latest version of the Script-O-Matic from the Microsoft
scripting page.  It can generate Perl code, and might help you by
letting you see more coding examples.

6.  Sometimes you may need to use the valof() function from Win32::OLE
to mimic byval.

7.  If you get stuck, feel free to ask the list.

BONUS:  It might be worth the money to buy the ActivePerl Dev Kit if
you're going to do this a lot.  It comes with a VB->Perl converter that
works great.




-----Original Message-----
From: Ryan Frantz [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 01, 2006 2:10 PM
To: beginners@perl.org
Subject: Perl and CDO

Perlers,

 

I've been researching Perl's support for CDO and found from a few
sources (namely ActiveState mailing list archives) that it's possible to
make a(n almost) one-to-one conversion of say, VBScript code to Perl
using Win32::OLE.  Do any of you know of any decent references for CDO
support in Perl?  I'm basically looking for information regarding how
the syntax compares between VBScript and Perl so that I can make sense
out of what I'll eventually be doing.

 

Ryan



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to