Can I name an anonymous array in Perl?

后端 未结 4 532
野趣味
野趣味 2021-01-13 05:06
#!/usr/bin/perl -w

use strict;

my $aref = [1, 2, 3];
my @a = @$aref;              # this line
$a[1] = 99;
print \"aref = @$aref\\n\";
print \"a = @a\\n\";
<         


        
4条回答
  •  悲&欢浪女
    2021-01-13 06:09

    To expand on Borodin's answer, I've tested this with the Lexical::Alias module:

    #!/usr/bin/perl -w
    
    use strict;
    use Lexical::Alias 'alias_a';
    
    my $aref = [1, 2, 3];
    my @a;
    alias_a(@$aref, @a);
    $a[1] = 99;
    print "aref = @$aref\n";
    print "a = @a\n";
    

提交回复
热议问题