2006-01-14

Perl object is just a blessed hash

To work on a small testing utility, I have to pick up perl again. Fortunately my memory still served me well until I got into this problem. How to trun a hash into object. After a little reading of my Learning Perl book. I figured out how it works. Once you understand perl object is just a blessed hash, then the solution is clear.

============================
package MyTest;

use strict;

my %hash = (color=>"red", shape=>"round");
my $hashref = \%hash;

sub not_typical_new {
my ($proto, $arg) = @_;
my $class = ref($proto) || $proto;
my $self = $arg;
bless ($self, $class);
return $self;
}

my $obj = mytest->not_typical_new($hashref);
print $obj->{color}, "\n";

Added a nice JSCalendar to the blogger

I added a nice JSCalendar to my blog. The instructions from ecmanaut helped. The first part is relatively easy. But the seconf part is difficult to follow. I ended up have to dig into the source code to find out how it works. After a hour or so, I finally figured out the basic functions. The challenge is because I used a customized template so that many CSS tags used by the scripts are not included. I have to change the template to include al l those CSS tags just to make the calendar work. I still cannot get the title hint to work as it requires more template change which I am not willing to spend more time. So I stopped here. But it is good enough for me now.

The del.icio.us tag script does not get along with Google's tools bar

I added the del.icio.us greasemonkey script so that I can create the bookmark after the post. However, it stopped working today. After a search on google, I learned that the script, for some reason, does not work with Google's toolbar extension. After remove the Google's toolbar, it works just fine. :(