VB vs PERL

I have had to support VB Script for a while now. While I would rather not use it, I really don’t have many options. It is needed to run actions on Windows servers and desktops, it is readily supported out of the box, and it kinda works.

Recently, we needed a script that would run at startup that would replace a configuration line in a settings file with an updated line. Basically, we needed to search the file for a the string that stated that the line was a certain config parameter, then replace that entire line with the new version of that parameter. Since this is running on everyone’s desktops, I would have to write it in VB Script.

Let me tell you, this is no easy task. I finally found a way to do it, here is the code for it.

strComputer="."

Set RegularExpressionObject = New RegExp
With RegularExpressionObject
  .Pattern = "StringToLookFor"
  .IgnoreCase = False
  .Global = True
End With

strReplace = "StringToInsert"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\SomeFile.txt",1)

Do Until objFile.AtEndOfStream
  strLineText = objFile.Readline
  expressionmatch = RegularExpressionObject.Test(strLineText)
  If expressionmatch Then
    strNewText = strNewText & strReplace & vbCrLf
  Else
    strNewText = strNewText & strLineText & vbCrLf
  End If
  Set expressionmatch = Nothing
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile("C:\SomeFile.txt",2)
objFile.WriteLine strNewText
objFile.Close

Set objFile = Nothing

That was not the easiest thing to figure out. Just for fun, I wrote the same thing in PERL.

open (TXTFILE, "C:\SomeFile.txt") || die "Read error for $!\n";

while ($temp_line = ) {
	chomp ($temp_line);
	if ($temp_line =~ /.*(StringToLookFor).*/) 
	{ $txt_line = "StringToInsert"; } else
	{ $txt_line = $temp_line; }
	$output .= $txt_line . "\n";
}

close (TXTFILE);

open (TXTFILE, ">C:\SomeFile.txt") || die "Write error for $!\n";
print TXTFILE $output;
close (TXTFILE);

exit (0); 

Without blank lines for spacing, or any comments, there are 25 lines of VB Script and 12 for PERL. Now, I did cheat a little with the PERL script. I usually like the make it a little neater, and using strict variable declarations. Switching to strict variables adds 5 lines, and then my usual layout adds another 4, for a total of 21 lines.

Now, I know that comparing raw lines of code is not a valid comparison of two languages. So what is? I like to look at how, in this case, each handles Regular Expressions.

VB: You have to declare an object as a regular expression object. Then, you define each aspect of it, and then you have to call it with .Test(variable) to test against the string in the variable. Don’t get me started on that damn Hungarian Notation of putting str before every string, or obj before objects. Oddly, I couldn’t find the notation for a regular expression object.

PERL: You simply call the variable with a =~, then you can use // to basic pattern match. If you wanted to actually replace the string in that line, you could use tr///, or if you wanted to just return part of the original string, s//.

Actually, the calls to open and close to files are very similar in length. Therefore, the real difference is the code to do the string comparison. It is just weirdly convoluted in VB. Not ass backwards, just convoluted. Hell, ass backwards would have been bad enough, the convoluted just makes it weird.

Advertisements

A beautiful confidentiality notice

I just received an ad, and this was the included Confidentiality Notice. While it contains the usual violations of common sense and legal theory, I really love the last line. Go ahead and read it.

Confidentiality Notice: The information contained in this e-mail transmission is intended only for use of the individual or entity named above. This e-mail transmission, and any documents, files, previous e-mail transmissions or other information attached to it, may contain confidential information that is legally privileged. If you are not the intended recipient of this e-mail transmission, or the employee or agent responsible for delivering it to the intended recipient, you are hereby notified that any disclosure, dissemination, distribution, copying or other use of this transmission or any of the information contained in or attached to it is strictly prohibited. If you have received this e-mail transmission in error, or you do not wish to receive any further communications from us, please immediately notify us by return e-mail transmission or by telephone at the number above or at the address above, and destroy the original e-mail transmission and its attachments without reading or saving it in any manner.

So, if I do not wish to receive any further communications from them, then I can reply to the email and request to be left alone, or I can call their phone number (which was not included in the email, contrary to the notice), and all is good. But wait! I also have to destroy the email, without reading it. Huh? How the hell am I expected to get this far in the email and follow the instructions, without reading it?

I just love this stuff sometimes.

Most. Disgusting. Keyboard. Ever.

Folks, this is disgusting. I had to replace this keyboard just the other day, and I really felt like I needed a hazmat cleaning afterward. The reason it was replaced was because the letters on the keycaps were fading. I know this means it was in use for a long time, but please, this is not necessary.

Also, PLEASE DO NOT LOOK AT THIS IF YOU MIGHT FEEL QUEASY OR LOOSE YOUR LUNCH!

click to open full image in a new window

Sabine Pass Schools and how to handle Hurricane Ike

Well, they finally made the call to evacuate Sabine Pass, which is right on the Gulf Coast of Texas without any protection from storms at all. Last night, the Sabine Pass ISD had a posting saying that school would be out on Friday, Sept 12, because they “anticipated… rising water” on the main highway in and out of town. However, they daw was supposed to be an in-service day for teachers. Meaning, they didn’t want to strand students, but teachers were OK!

However, today’s page has been updated! Both Thursday and Friday is out, except they still seem to be in-service days for teachers!

The new Microsoft ad campaign

Huh? Wait, no really, huh?

I finally saw what I believe is “the” Seinfeld-Microsoft ad on youtube. First, I thought I had the wrong video, and this had to be something else, but then again, I can’t believe there are that many videos of Bill Gates and Jerry Seinfeld out there.
Continue reading

Windows Server 2008 Standard – Workstationed

Well, with how well Vista is going, I was wondering if we were going to try and support XP Pro for years after it is officially dead.

Then, I came across this site the other day, which got me to wondering if we could use Windows Server 2008 as an option.
Continue reading

The 13 year old LCD monitor. What?

Well, the other day I contacted a nameless company that sells lots of computers to get an LCD monitor replaced. Seems this monitor decided that it didn’t really want to work anymore. OK, it didn’t want to work from the VGA port anymore. It would power up, show an image, then quickly go to a split white/black screen, then go to a full white screen. Using the DVI port, it worked fine.

So, I contacted their support to get it replaced. They asked for the serial number of the machine it is supposed to be attached to, and I said truthfully, “I have no idea.” See, like many large places, monitors have been moved on an as-needed basis. Heck, it is possible that this monitor was bought as part of a large order, for an existing system when we upgraded to 2 monitors per desk some years ago. After going around about this for about 15 minutes, they decided that I should give them the Serial Number for the monitor itself, and go with that.

So, I give them the serial number from the monitor, in which they reply that the monitor is out of warranty, since it was made in 1995. I was sure that this model didn’t exist in 1995; a 19″ LCD, with DVI input… yeah, didn’t exist in 1995, I’m sure of it. I mentioned this to them and they said that according to that serial number, it was made in 1995. I had them verify that serial number with me. They checked, and held to their position that the monitor was 13 years old and, therefore, out of warranty. I didn’t make a big fuss, I was pretty sure this monitor was a replacement for a different 19″ monitor which had died, and was now past the 3 year warranty period.

But still, kinda funny. I am included some pictures of the monitor, just for fun. Oh yeah, since the DVI input works fine, I have it on my desk right now.

The unnamed company\'s 13 year old monitor.

The unnamed company\'s 13 year old monitor.