in reply to Re: Dots and cargo-cult programming
in thread Dots and cargo-cult programming
That understanding will help you, but there will be other differences. For instance, this.that = 2 in VB would be $this->{that} = 2 in Perl. But something like a method call would be this->DoSomething.
Using Win32::OLE isn't as straightforward as you might want it to be. The biggest things to look out for is that when you're setting properties, you're going to be using a hash, and there are other times when you're going to be using lists. For example..
This is some DB code that uses ADO..
and someting similar in VB (sorry, this below is from some ASP a customer asked me to put together. Above is something I use. They don't perform the same task, but you should be able to see what mirrors what.#!/usr/bin/perl -w use strict; use Win32::OLE; my $strCon = "Provider=SQLOLEDB; Data Source=XXXXX; Initial Catalog=SM +S; " . "User ID=XXXXX; Password=XXXXX"; my $strSql = "SELECT System_DATA.Name0, datediff(dd, LastUpdateDate, g +etdate())" . " 'age' FROM SoftwareInventoryStatus INNER JOIN System_DATA on " . "System_Data.MachineID = SoftwareInventoryStatus.ClientID WHERE + " . "(datediff(dd, LastUpdateDate, getdate()) > 30)" ; my $objCon = new Win32::OLE("ADODB.Connection"); my $objRecordset = new Win32::OLE("ADODB.Recordset"); $objCon->{'ConnectionString'} = $strCon; $objCon->Open; $objRecordset->Open($strSql, $objCon); while (not $objRecordset->{'EOF'}) { print $objRecordset->{'Name0'}{'Value'}, "\t"; print $objRecordset->{'age'}{'Value'}, "\n"; $objRecordset->MoveNext; } $objRecordset->Close; $objCon->Close;
and what was a little confusing to figure out is that in VB, You can refrence the "Name0" field as objRecordset("Name0") but in Perl it's $objRecordset->{'Name0'}{'Value'} I personally prefer Perl, but with things like Win32::OLE it's a lot of poke and hope to figure out just how you have to access properties and methods.Option Explicit Dim objConnection, objRecordset, strSQL, Name Set objConnection = Server.CreateObject("ADODB.Connection") objConnection.ConnectionString = "Provider=SQLOLEDB; Data Source=XXXX +; Initial Catalog=SMS; User ID=XXXX; Password=XXXX" objConnection.Open Set objRecordset = Server.CreateObject("ADODB.Recordset") strSQL = "SELECT Name0, MachineID FROM System_DATA WHERE MachineID >= + 0 ORDER BY Name0" objRecordset.Open strSQL, objConnection
|
---|
In Section
Meditations