|
Array::Splice - Splice aliases into arrays |
Array::Splice - Splice aliases into arrays
use Array::Splice qw( splice_aliases push_aliases );
my @a = qw( foo bar ); my $x = 'baz'; splice_aliases @a,1,0,$x; $x = 'zoop'; # Changes $a[1] print "@a\n"; # foo zoop bar
sub wrapped_foo {
push_aliases my @args => @_; # Copy @_
some_wrapper(sub { foo @args }); # &foo called with orginal arguments
}
This module does splicing of arrays for real. That is does exactly
the same as the builtin splice function except that the inserted
elements are existing scalar values not copies of them.
One possible use of this is to copy the @_ array but I'm sure that there are others.
This module does not export anything by default.
splice except that the scalar values that
are the elements of LIST get spliced directly into ARRAY rather being
copied. Unlike the builtin splice OFFSET and LENGTH are not
optional since if you are not giving LIST then splice_aliases is
just exactly the same as splice.
This is unlikely to be useful for tied arrays but for the sake of
uniformity, splice_aliases() tries to call a SPLICE_ALIASES() method
on the object to which the array is tied.
splice_aliases that emulates the builtin push
except that LIST gets spliced directly into ARRAY rather being copied.
splice_aliases that emulates the builtin unshift
except that LIST gets spliced directly into ARRAY rather being copied.
Brian McCauley, <nobull@cpan.org>
splice in the perlfunc manpage.
|
Array::Splice - Splice aliases into arrays |