in reply to Re^2: a referencable array slice (so assigning to it modifes the original)
in thread a referencable array slice (so assigning to it modifes the original)
Like I said, I can't test this, but I think I see an error in your code:
use strict; use warnings; use Data::Alias; use Data::Dumper; my @foo = qw( A T T G C T T G C T T C ); alias my @view = ( @foo[1,2], @foo[5,6] ); alias push @view, @foo[7,8]; # Added alias here. map {$_='$'} @view; print Dumper \@foo; print "nok" if $foo[7] ne '$';
You added copies of $foo[7] and $foo[8] to @view. So you wound up with something like:
When you wanted:@view |- 0: alias $foo[1] |- 1: alias $foo[2] |- 2: alias $foo[5] |- 3: alias $foo[6] |- 4: 'G' \- 5: 'C'
@view |- 0: alias $foo[1] |- 1: alias $foo[2] |- 2: alias $foo[5] |- 3: alias $foo[6] |- 4: alias $foo[7] \- 5: alias $foo[8]
I haven't been able to play with this, but it feels like you need to think about each scalar as either a normal value or an alias--unless you are working with whole aggregate aliases, in which case the aggregate is aliased. If my understanding is correct, in the example above we are not using whole aggregate aliases (just a slice), so individual aliases are assigned to @view.
TGI says moo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: a referencable array slice (so assigning to it modifes the original)
by muenalan@cpan.org (Initiate) on Jun 18, 2008 at 18:47 UTC | |
by TGI (Parson) on Jun 18, 2008 at 20:53 UTC |