[EMAIL PROTECTED] wrote:
On Mar 25, 8:50 am, [EMAIL PROTECTED] (Sharan Basappa) wrote:

Is there a way I can copy only part of an array into another array.
For example, I want to copy only first 8 elements of source array
into destination array.

You can use the splice( ).  See example:

#!/usr/bin/perl - w
use strict;
use warnings;

my @array1 = qw(1 2 3 4);
my @array2 = qw(3 4 5 6);

print "@[EMAIL PROTECTED]";
push(@array2,splice(@array1,2,2));
print "@array2\n";

splice() will remove the elements from the first array so it is not just copying them it is moving them.


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/


Reply via email to