about photos bookshelf portfolio blog home
Begin main content

Non-orthogonality of Perl

When it comes to switching between objects and natives, Perl OO is not quite as orthogonal (or DWIM) as I would like. For instance, assuming I have a class:

package MyArray;
...
sub push { ...}

Then I can treat an instance of that object as an object with a method push, or as a kindof array (kindof, because of course an actual array would have @ for its sigil):

# these are equivalent:
$instance->push(1);
push $instance, 1;

I don't, however, have the orthogonal behaviour with an actual array ref:

# this works:
push @$arrayref, 1;
# this doesn't:
$arrayref->push(1);
# nor, of course, does this:
@$arrayref->push(1);

What I would like is more DWIM than real orthogonality, but if Perl's not DWIM then it's nothing! I guess I'm just wishing for real native array objects like Ruby (sigh).

01:54 PM, 25 Jun 2007 by Mark Aufflick Permalink

bah!

haven't you seen autobox or Moose::Autobox?

by Unregistered Visitor on 06/25/07

Watch me pull a rabbit out of this hat...

I am in fact playing with Moose this very instant. autoboxing makes me think, unfavourably, of Java - but I'll check it out. Thanks for the tip!

by Mark Aufflick on 06/27/07

autobox looks cool

I checked out autobox on cpan - it actually looks quite cool, so thanks for the tip! Of course it still doesn't allow for overriding == etc., but it's good nonetheless.

by Mark Aufflick on 07/01/07

Add comment