于 2012-1-16 1:18, Pradeep Patra 写道:
It works and displays 1-12. But I need something different because i
dont know the value of "n" beforehand. So I decided to use a for loop.
I tried push but it did not work. I would appreciate any help to merge
multiple array elements preferably not using any library function like
push etc.

"push" is the built-in function of Perl, not an external library function, so why not using it? Consider the code below, though eval a string is considered bad way generally.

use strict;

my @a1 = (1,2,3);
my @a2 = (4,5,6);
my @a3 = (7,8,9);
my @array;

for (1..3) {
   push @array, eval('@a' . $_);
}

print "@array","\n";


HTH.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to