Perl Objects


Using object oriented techniques in perl might feel a bit strange if you are moving to perl from Java, C++ or some other object oriented programming langauge. Having to bless objects might seem a bit off putting if you are not religiously inclined.

Unlike java, in perl a constructor does not have a special name associated with it but if you name your constructor as new you can make use of the familiar $obj = new MyClass() syntax to obtain a new instance. Though new is a reserved word in most other OO languages, it most certainly isn't a keyword in perl.

Another curious thing about perl from a java programmers perspective is that the getter, setter technique that you use to get or set class methods smells a lot different in perl. Typically you would use a $obj->property() to retrieve a property and $obj->property($value) to set a property.

Of course both this technique and the getter, setter technique used in java are not part of the language definitions but part of the standard practice or as some people might say a religious practice.

Tom Christiansen's Object Oriented Perl tutorial (pertoot) is one of the most well written pieces of documentation I have ever read. He should consider becoming a novelist.

Foot Note:

My first hello, world in perl dates from 1997 but I didn't both with object oriented perl at the time because at the time the only 'serious' language I knew was C. Then I stayed away from perl from 1998 to 2003, so for me this is a 'relearning' experience.

comments powered by Disqus