in reply to (Expert) Splicing a slice
(There is no spoon, eh?)
Caveat: what I know of perlguts I mostly understand from reading PerlGuts Illustrated. From the "AV" section of that, the actual array storage data structure consists of pointers to the contents of each element of the array. That would suggest that you could use XS to get the pointers in two separate arrays to point to the same contents. I think that Data::Alias should be able to do that for you like this:
use Data::Alias; alias @x = @y; $x[1] = 2; # should make $y[1] == 2
If applied to a slice, that might get part of what you're looking for -- one array that is really just an alias a subsection of another array. The problem is that your example with splice won't work -- as splicing will just screw up the offsets, e.g. you'd get something like $x[2] pointing to $y[3]. You might be able to manually handle it, splicing and re-aliasing or something, but I'm not sure if the overhead of that leaves you with any performance gain.
Update: Data::Alias doesn't seem to be available for ActiveState. However, Lexical::Alias is and appears to be do the same kind of thing, albeit with different syntax, if that's an important consideration.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: (Expert) Splicing a slice
by xdg (Monsignor) on Sep 28, 2005 at 16:25 UTC | |
by dragonchild (Archbishop) on Sep 28, 2005 at 18:55 UTC | |
by ikegami (Patriarch) on Sep 28, 2005 at 16:40 UTC | |
by xdg (Monsignor) on Sep 28, 2005 at 18:19 UTC |