develooper Front page | perl.perl5.porters | Postings from July 2020

Pass by reference (alias) when using signatures

Thread Next
From:
Eric Brine
Date:
July 14, 2020 15:21
Subject:
Pass by reference (alias) when using signatures
Message ID:
CALJW-qE8z+arzGaeU2jf2WqypMHsrsb=U6UBahGRQ4M5GBSNNw@mail.gmail.com
It doesn't seem to be possible to pass by reference when using sub
signatures. The default sure isn't.

sub foo ($arg) {
   $arg = 456;
}

my $x = 123;
say $x;   # 123
foo($x);
say $x;    # 123

In the style of refaliases, wouldn't it make sense to support

sub foo (\$arg) {
   $arg = 456;
}

my $x = 123;
say $x;   # 123
foo($x);
say $x;    # 456

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About