pragmaperl

What is perl feature, postderef?


I see use experimental 'postderef' and use feature 'postderef' being used in Moxie here on line 8. I'm just confused at what it does. The man pages for experimental are pretty vague too,

allow the use of postfix dereferencing expressions, including in interpolating strings

Can anyone show what you would have to do without the pragma, and what the pragma makes easier or possible?


Solution

  • What is it

    It's simple. It's syntactic sugar with ups and downs. The pragma is no longer needed as the feature is core in 5.24. But in order for the feature to be supported in between 5.20 and 5.24, it had to be enabled with: use experimental 'postderef'. In the provided example, in Moxie, it's used in one line which has $meta->mro->@*; without it you'd have to write @{$meta->mro}.

    Synopsis

    These are straight from D Foy's blog, along with Idiomatic Perl for comparison that I've written.

    D Foy example                    Idiomatic Perl
    $gimme_a_ref->()->@[0]->%*       %{ $gimme_a_ref->()[0] }
    $array_ref->@*                   @{ $array_ref }
    get_hashref()->@{ qw(cat dog) }  @{ get_hashref() }{ qw(cat dog) }
    

    These examples totally provided by D Foy,

    D Foy example                    Idiomatic Perl
    $array_ref->[0][0]->@*           @{ $array_ref->[0][0] }
    $sub->&*                         &some_sub
    

    Arguments-for

    Arguments-against

    not at all provided by D Foy

    Sources