Postfix Deref?

I really like the increased development pace for Perl5 starting with 5.10. It has led to many nice features in a relatively short time and I´m grateful for that. Occasionally however, the need for speed imho trumps sanity and reason...

In the past, some weirdo things crept in like the overly complex smartmatch, but usually I tend to have a calm look at all these changes and just wait'n'see if I adopt them (I certainly didn´t have a clue if smartmatch was a good idea or not, back when it was introduced).
I´ve still not decided on auto-deref.

This time around (i.e. Perl5 5.20), though, there´s something I practically hated at first sight: Postfix Dereferencing syntax. No idea why - it just looks completely awkward to me.

TIMTOWTDI´s nice, but sometimes less is more.

Unfortunately Perl6 seems to have the same tendency for "syntax creep" in some places: cf. typed arrays. "my num @nums;" and "my @nums of num;" - yeah, ok. But why also "my @nums[-->num];"???

Being able to apply TIMTOWDI on a high level (algorithms, functional or object oriented programming, etc.) is great because for complex problems being able to select a certain solution strategy can make a huge difference.
But so many ways to express the same trivial intention imho mostly serves as a barrier especially for newcomers when trying to understand some published code.


I, too, fail to see the attraction of postfix deref. It must be just about the least awaited new Perl feature.

(Just for fun, I'll note that the scalar postfix deref can be made to work - albeit with warnings and without interpolation - in older versions of Perl.

local $* = sub { ${+shift} };
my $foo = \42;
print $foo->$*, "\n";


I suppose one thing that's nice about it is that you can avoid curlies for dereferencing deep structures. e.g. the expression

@{ $foo->{bar}{baz} }

can become


assuming I understand it correctly.

It does look weird, though. But we are talking about Perl. :)

And four punctuation characters to dereference an array is an improvement over the current three?

If I were to have my pick of features to add to core, then I'd choose autoboxing way ahead of this. Autoboxing would actually allow us to define a nice syntax for postfix dereferencing, along the lines of:


Leave a comment

About Mike Sanders

user-pic Nope.