in reply to a referencable array slice (so assigning to it modifes the original)

Perl has an easy way to create an array with elements aliased to arbitrary other things: subroutine parameters.
use Data::Dumper; my @dna = qw(A T T G C); print Dumper \@dna; my $view = sub { \@_ }->(@dna[1,2]); $view->[0] = 'x'; $view->[1] = 'x'; print Dumper \@dna; $view = sub { \@_ }->( $dna[4], @$view[1..$#$view] ); $view->[0] = 'y'; $view->[1] = 'y'; print Dumper \@dna;
  • Comment on Re: a referencable array slice (so assigning to it modifes the original)
  • Download Code