The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Data::PostfixDeref - Allow ->[] ->{} as an alternative to @{ } %{ }


    use Data::PostfixDeref;

    my $x = { a => [1, {b => [2, 3]} ] };

    print for $x->{a}[1]{b}[];
    print for keys $x->{a}[1]{};
    push $x->{a}[], {c => 4};


This module installs a hook into the Perl parser, that allows the syntax


as an alternative to

    @{ $x->[0] };

and similarly $x->[0]{} for %{ $x->[0] }. The idea is to make expressions like

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

less unwieldy. These expressions can be used anywhere the equivalent @{ } expression would have been valid; in particular, they can be passed to (\@)-prototyped functions, and builtins like keys and push.

Disallowed syntax

Any further subscripts, such as


will elict the error 'Additional subscripts after ->[] are forbidden' (but see "TODO" below).

Attempting to interpolate a hash into a string with


will fail with 'Can't interpolate hash'.

Switching it off

The hooks installed can be removed with

    no Data::PostfixDeref;

Note that all code compiled while the hooks are in effect will get the new syntax, even code in different packages or different files. Also note that once the hooks are removed, string-evals won't allow the syntax, even if the surrounding code would.


Since we don't actually replace the Perl parser, the new syntax is not as general as it might be. The only cases that will work are

  • Directly after another subscript, like

  • Directly after a list slice, like

        ([1], [2])[1][]
  • Directly after a sub call (with or without parameters), like

        get_aref($x, $y)->[]
  • Directly after a method call (with or without parameters), like


In particular, neither


with no intervening subscript nor more complicated expressions like

    ($firstaref || $secondaref)->[]

will work (they will still be considered syntax errors); the first due to an artefact of the Perl parser (specifically, that CHECKOP is never called for OP_PADSV), and the second because the question of precedence makes it impossible without being properly integrated into the yacc parser.



Use %^H to activate the hooks lexically rather than globally. This will only work under 5.10.


Allow the syntax

    $x->[0][][1, 2, 3]

for array slices, and

    $x->[0]{}{qw/a b c/}

for hash slices. (Currently these are both still syntax errors.)


Please report any bugs via


Copyright 2008 Ben Morrow <>

This module is released under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 145:

You forgot a '=back' before '=head1'