[EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] into the middle of @players without removing any elements from @players.so i've done the following... #!/usr/bin/perl -w # extracting elements using splice @players = ("ryno", "fukudome", "grace", "banks", "santo", "soto", "marmol", "sori", "bigZ", "pie"); @dump = splice(@players, 0,2, "theriot", "sosa");
splice() modifies @players, starting at element 0 ("ryno"), with a length of 2 and replace those with the list ("theriot", "sosa") and return the elements that were removed ("ryno", "fukudome").
print "The original array is @players\n";
At this point @players has already been modified so it is not the original array.
print "The players dumped after the splice are: @dump.\n"; print "The spliced array is now @players.\n"; ...but I'm not sure I'm doing the splice correct, because the first line prints all the players including the ones stated in @dump. should i be using negative offset or length?
If you want to put ("theriot", "sosa") into the middle of @players without removing any of its elements then you have to use a length of 0.
splice @players, 0, 0, "theriot", "sosa"; Which could also be written as: unshift @players, "theriot", "sosa"; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
