Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Dots and cargo-cult programming

by joefission (Monk)
on Jul 15, 2001 at 02:50 UTC ( [id://96794]=note: print w/replies, xml ) Need Help??


in reply to Dots and cargo-cult programming

I've got a slightly different take on the . vs -> syntax grumblings.

I have Win32 System Administration background. I was told by someone I deeply respected, that I should learn Perl if I wanted to be a "real sys admin" (curiously he didn't mention the OS...too easy a target, I guess). There are quite a few tools out there that use VB and VBScript for NT Admins. I laughed at people who used VB because, well, it was BASIC (yeah, just a tad naive).

However, quite a few books and people use VB for examples on how to script NT administration tasks. One of these books is ADSI ASP Programmer's Reference(1998,wrox, Steven Hahn). I wanted to know more about ADSI and this book had lots of info, even with it being VB-centric. I figured I could port it to Win32::OLE. I was wrong. I didn't want to learn VB so I could learn how to do it in Perl. So this book doesn't even have the spine cracked, because I found other Perl modules aside from OLE to keep me busy.

I'm very embarrassed to say that I had no idea that . meant -> until it was brought up in the Perl6 discussions. I guess I can go back, break open that book, and translate the . to ->.
If Perl6 uses the . syntax, it might make it easier for people like me to read and learn from other code. Even if it is VB.

Replies are listed 'Best First'.
Re: Re: Dots and cargo-cult programming
by rchiav (Deacon) on Jul 16, 2001 at 03:05 UTC
    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..

    #!/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 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.
    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
    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://96794]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2025-05-20 03:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.