http://www.perlmonks.org?node_id=1180130


in reply to Improve readability of Perl code. Naming reference variables.

There's a new feature that appeared in "developer release 5.25.3". It's mentioned in "(5.25.3) perldelta: Declaring a reference to a variable". Details are in "(5.25.3) perlref: Declaring a Reference to a Variable". The text of that last link starts with "Beginning in v5.26.0, ...": so, if you don't want to install a developer version (the latest is 5.25.9), you probably won't have long to wait for a stable one.

I think this is the sort of thing you were after:

#!/usr/bin/env perl use 5.025003; use strict; use warnings; no warnings 'experimental::refaliasing'; use experimental qw{refaliasing declared_refs}; use feature 'declared_refs'; { my $str = \'string'; my $list = [qw{a b c}]; my $map = {x => 24, y => 25, z => 26}; func($str, $list, $map); } sub func { my (\$string, \@array, \%hash) = @_; say $string; say "@array"; say "$_ => $hash{$_}" for sort keys %hash; return; }

Sample run:

$ perl -v | head -2 | tail -1 This is perl 5, version 25, subversion 9 (v5.25.9) built for darwin-th +read-multi-2level $ pm_1179933_test_exp_declared_refs.pl string a b c x => 24 y => 25 z => 26

Important: Do note that this feature is experimental; subject to change; and, as such, not suitable for production code.

— Ken