Just Another Blog

Are you thinking what I'm thinking?

Wednesday, July 14, 2004

Perl is driving me crazy...

Recently I'm setting up Blosxom (pronounced "blossom", or "blogsome") as the blog platform for our department. It is an extremely simple Perl script that scans a directory (recursively) for .txt files and displays them accordingly as blog posts.

If you has been visiting here regularly, you should have known that I've learnt a little bit about PHP in the previous month. So now I finally know about one should declare a variable in PHP like $var1: that's how Perl does it.

However, Perl has so much difference from what I've learnt before. Now I'm almost a newbie (again). For example, one write else if (...) in C/C++/JavaScript and elseif (...) in PHP. But in Perl, you'll see something new: elsif (...)! Guess that the Perl inverter is too lazy to type an extra "e" and space... -__-|||

There are many more weird operators and syntax that I've never seen. But I won't list them here or the page would be toooooo long...

One thing that I don't like about Perl is the lack of pointers. Say I need to make changes to a variable with a very long reference chain (e.g. $hash->{'a'}->{'very'}->{'long'}->{'reference'}) many times in a sub (subroutine/function). What I want is to save this reference to a temporarily pointer, and then dereference it to assign new value to it. In JavaScript, reducing object chains can help improve performance. For example, instead of:

for ( var i = 0; i < window.document.forms[0].length; i++ )
{
    window.alert( window.document.forms[0].elements[i].value );
}

one should save the references with variables:

var myForm = window.document.forms[0];
for ( var i = 0, len = myForm.length; i < len; i++ )
{
    window.alert( myForm.elements[i].value );
}

or use for-in (not support in IE though):

var myForm = window.document.forms[0];
for ( var i in myForm )
{
    window.alert( myForm.elements[i].value );
}

I know there are something known as soft/hard references but I can't get it works. Maybe I typed it wrongly. By the way, tell me if you know how to do it.

Anyway, I'm ok with it. Just give me some time... I think I will soon write some very l33t Perl programs/modules (that no one will understand)!

0 Comments:

Note that troll and spam comments will be deleted without any notification.

Post a Comment

<< Home