typestar

Postfix dereference in Perl

Two spellings of the same deref: sigil-first @$ref and postfix $ref->@*.

use strict;
use warnings;

my $nums  = [3, 1, 4, 1, 5];
my $entry = { name => "ada", langs => ["perl", "c"] };

my @classic = @$nums;        # sigil-first deref
my @postfix = $nums->@*;     # postfix reads left to right
print "classic: @classic\n";
print "postfix: @postfix\n";

print "langs: ", join(", ", $entry->{langs}->@*), "\n";
print "keys: ", join(" ", sort keys $entry->%*), "\n";
print "count: ", scalar $nums->@*, "\n";

How it works

  1. @$nums and $nums->@* produce the same list; postfix reads left to right.
  2. Deep chains stay linear: $entry->{langs}->@* needs no wrapping braces.
  3. $entry->%* derefs a hashref, so keys and sort apply directly.
  4. scalar $nums->@* counts elements, just like the sigil form would.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
430
Tokens
110
Three-star pace
70 tpm

At the three-star pace of 70 tokens a minute, this run takes about 94 seconds.

Type this snippet

Step 3 of 3 in Files & modern Perl, step 24 of 27 in Language basics.

← Previous Next →