teun-arno has asked for the wisdom of the Perl Monks concerning the following question:
I have a problem with the splice function ..
my $col = 1 ; my @arr = (qw/one two three four five / ); my @indexes = ( 0 .. $#arr ) ; print ">> @arr[@indexes]\n"; print ">@indexes<\n"; # show the indexes ! my $key= splice @arr, $col,1; # remove $col from @arr. # You would expect that @indexes are NOT changed; However : print ">@indexes<\n"; # still the same indexes are shown. print "$key : @arr[@indexes]\n"; # this is NOT expected, but I do not +understand this behaviour. print ">@indexes<\n"; # still the same indexes are shown.
Output :
>> one two three four five >0 1 2 3 4< >0 1 2 3 4< two : one three four five >0 1 2 3 4<
I did not change @indexes in any way, however the splice did some nasty things!! can somebody explain ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: splice and indexes
by johngg (Canon) on Nov 29, 2018 at 00:11 UTC | |
|
Re: splice and indexes
by Anonymous Monk on Nov 28, 2018 at 23:00 UTC | |
|
Re: splice and indexes
by haukex (Archbishop) on Nov 30, 2018 at 08:41 UTC |