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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.