When the poll was published I truthfully answered with "Never". However, since then I find myself checking whenever I write @{$stuff} whether it would be more readable as a postfix dereference. Eily already brought up one border case in Re^2: I use postfix dereferencing ..., but I'd agree with him that in this case an intermediate variable would be preferable.
Today I stumbled over another use case where I am now tempted to use postfix dereferencing: I'm pulling several attributes out of an object, some of which are array references... and I need copies of the arrays. In that case, scalars and arrays "line up" better with postfix dereferencing. SSCCE:
use 5.020; use feature 'postderef'; package Object { use Moose; has string => (is => 'ro', isa => 'Str'); has aref => (is => 'ro', isa => 'ArrayRef'); }; my $object = Object->new(string => 'Hello World', aref => [1,2,3] ); # Traditional dereferencing my $string = $object->string; my @list1 = @{$object->aref}; # Intermediate variable my $string = $object->string; my $aref = $object->aref; my @list2 = @$aref; # Postfix dereferencing my $string = $object->string; my @list3 = $object->aref->@*;
What needs work in my opinion is the documentation in perlref. It claims that (emphasis mine) Postfix dereference should work in all circumstances where block (circumfix) dereference worked, and should be entirely equivalent. "Should work"? Except when it doesn't? I'd prefer not to rely on syntax which should work. A bit later it says: Note especially that $cref->&* is not equivalent to $cref->(), and can serve different purposes. I admit that I'm too lazy to work out the difference and have decided not to use the ->&* construct instead.
In reply to Re: I use postfix dereferencing ...
by haj
in thread I use postfix dereferencing ...
by hippo
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |