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.

Advertisement

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.

Linux is going all schizo on us!

This post is way out of date, but what the hell, I think it is still valid.

ZDNet has provided some wonderful troll fodder in the form of the article “Linux and its identity crisis“.

So, it seems that Don Reisinger ran off and read some pissing and moaning between the various scheduler viewpoints, and tried to make a mountain out of a molehill.

Here is my review of the article:
Continue reading

Online black holes

Friday, September 15th, 2007, almost saw the creation of an online black hole. Before going any further, we must first look at the types of online black holes.

Micro Black hole
AKA: black hole of self-reference. This is where an article makes a direct reference back to itself, usually as support for, or an example of, what it is arguing about.

Example: A Something Awful article complaining about logical fallacies and poor argumentation practices used on Something Awful, with a link to itself as an example of such crappy argumentation.

Effect: Usually minor, such as the server hosting the page goes down or looses the page due to drive failure.

Mini Black hole
AKA: black hole of cross-reference.
An article written on a site, which supports articles, which references a news-headline site in its argument, which that headline site then links to the article.

Example: A Something Awful article criticizing all of the dick-heads and losers participating in flame-wars on the Fark site, following by a link and comment section on the Fark site about the article in question.

Effect: Loss of a server, most likely disappeared into the ether, sometimes takes a few user with it.

Major Black hole
AKA: black hole of circular reference.
This is when an article makes reference to one or more headline site, then one links to the article, which the other links to the other headlines’ site link to the article.

Example: Article on Something Awful criticizing Fark’s online comment threads and the flame-wars that can erupt. Slashdot then posts a link to the article. Finally, Fark posts a link to the Slashdot article and comments thread about the SA article.

Effect: Major loss. Can include servers, users, and small towns.

Now, Fridays near black hole was caused by this article about online criticism posted on Something Awful. This article was then referenced by the online news and comment site, Fark. Now, the only thing which stopped the formation of the black hole was the fact that the article itself did not directly reference, or link to, Fark.

Had this happened, most likely a server, and maybe a few registered users, would have disappeared. Has this happened before? One can not fully prove either way, but I doubt that the mysterious “Drew Curtis” has spilled as many beers on the servers as has been joked about. Maybe if the only beer around was Pabst Blue Ribbon, but since MC Router has started drinking, there is no way to find enough PBR to spill into a beer glass, much less a server.