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


in reply to Unifying namespaces of @name and $name to simplify dereferencing?

Did you see the refaliasing feature? Not that I'd ever use it, but it seems to address your wishes.

Read the the full details, available since 5.22.0


Enjoy, Have FUN! H.Merijn
  • Comment on Re: Unifying namespaces of @name and $name to simplify dereferencing?

Replies are listed 'Best First'.
Re^2: Unifying namespaces of @name and $name to simplify dereferencing? (experimental::refaliasing)(updated examples)
by LanX (Archbishop) on Mar 26, 2016 at 12:21 UTC
    Oh thanks that's indeed interesting, Perl core finally allowing aliasing of lexicals! :)

    ... not sure if it solves the all issues yet...

    But you know these new possibilities deserve a proper thread ...

    update
    hmm ... coupling is broken after assigning a new ref

    use 5.22.0; use feature qw/say refaliasing/; no warnings "experimental::refaliasing"; \my @a = my $a = [666]; say "noref: $a[0], ref: $a->[0], list: @a"; $a = [42]; say "noref: $a[0], ref: $a->[0], list: @a";
    -->
    noref: 666, ref: 666, list: 666 noref: 666, ref: 42, list: 666

    update

    at least passing arrays to arrays is possible now

    use 5.22.0; use feature qw/say refaliasing/; no warnings "experimental::refaliasing"; my @a = (666,42); test (\@a,\@a); sub test { (\my @sub, my $ref) = @_; say "noref: $sub[0], ref: $ref->[0], list: @sub"; }
    -->
    noref: 666, ref: 666, list: 666 42

    well the syntax when passing more than one argument is not very elegant, see duplicated my ... but at least it's consistent.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!