Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Improve readability of Perl code. Naming reference variables. [New Perl Feature]

by kcott (Archbishop)
on Jan 22, 2017 at 22:33 UTC ( [id://1180130]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1180130]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-09-10 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

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