mySQL/Perl Gripes

Last entry I whined about Perl’s appalling lack of a trim() function.

I forgot to add another Perl pet peeve: No comment blocks.

With most languages, you can place a “/*” before a code block and “*/” after the code block and have all lines – one to (no limit) commented out. (Note: Hopefully, it’s understood that the code comment open/close characters are sans quotation marks…).

Perl, in its infinite wisdom, does not allow this.

Each line must be commented with a pound sign: #

Example:


=======

PHP

=======

/*

// all five lines here are commented out

$myVar = ” Foo Bar “;

$myVar = trim($myVar); // now “Foo Bar”; full trim

$myVar = ltrim($myVar); // now “Foo Bar “; left trim

$myVar = rtrim($myVar); // now ” Foo Bar”; right trim

*/

======

Perl

======

# Note how I have to prepend EACH line with the pound sign,

# even multiple lines of comments, such as these two….

# $myVar = ” Foo Bar “;

# $myVar =~ s/^\s+|\s+$/; # returns “Foo Bar”

OK, no big dealie for these examples, but let’s take a real-world Perl example I was just working on.

I was doing a dataload, and – before I actually fired the SQL – I had several blocks of processing code and was printing out this or that line so I could see all was well.

Once we get to that point, then fire SQL.

I got to that point, but something barfed on the DB side. So I wanted to back out this or that block of processing code and print some additional debug statements.

But – to cut out any code block – I had to either:

  • Remove the code from the file (and paste it elsewhere so it’s not lost)
  • Put a pound sign before each line in the code block – up to 50 lines

Again – with most coding languages, you just wrap the code block in the “begin/end comment” characters. Done.

Ick. I think (not certain…) that Perl 6 is supposed to support multi-line comment tags, but … too late. Lots of pre-v6 code out there that doesn’t have this support. Lots.

MySQL Rant

While I’ve gotten over my initial reaction to mySQL (“It’s not a real database! Hell, Access has better ANSI support!”) and have grown quite fond of this DB, it still keeps biting me in the ass.

Note: I’m currently running v3.23x, simply because that’s what’s supported out on shared hosting sites (that I have to work with). Version 4 fixes – to a degree – the problem I’m going to bitch about right now.

I have square marks on my forehead from banging my head on the keyboard trying to make the following work in mySQL


UPDATE

table_1 (column_name)

SET

table_1.column_name = table_2.another_column_name

WHERE

table_l.id = table_2.id

Trivial, ja?

Nope.

Can’t do multi-table updates in pre v4.0.4 mySQL.

Ouch.

So, I had to write a script that pulled data from second table, stored (array) and then updated the first table.

Yes, this is solved now – in the v4 types, but subselects still are not (v4.1 will address this; won’t be a stable release until about November 2004).

In other words: MySQL is making great strides, but v3.23 – the current standard for most sites today – “offers” significant limitations.

But mySQL is moving in a good direction. Good. Because it does have some nice features.

Please just give me what I expect from any database!

End rants.