Andy Wardley <[EMAIL PROTECTED]> writes: > I'm trying to do the simplest thing with splice() but not seeing the > results I expect. It seems to go weird when I passed an array of > arguments rather than a direct list. > > my (@list, @result, @args); > > # first, the working example > @list = qw( a b c d e ); > @result = splice(@list, 3, 1); > > print "splice remains: @list\n"; # a, b, c, e > print "splice result: @result\n"; # d > > # now the not-so-working example > @list = qw( a b c d e ); > @args = (3, 1); > @result = splice(@list, @args); > > print "splice remains: @list\n"; # a, b > print "splice result: @result\n"; # c, d, e > > The summary: splice() seems to get confused if you call it as > splice(@list, @args). > > Am I missing something obvious?
Splice is prototyped @$;$$@ if memory serves. The prototype pushes the second argument into a scalar context. So C<splice @list,@args> becomes C<splice @list, scalar(@args)>, which becomes C<splice @list, 2>, which is what you've got. Of course, in Perl 6, you'd just do: C<splice @list, *@args>, but we don't have that yet. -- Piers "It is a truth universally acknowledged that a language in possession of a rich syntax must be in need of a rewrite." -- Jane Austen?