Re: Merging Multiple Array elements
- From: Jürgen Exner <jurgenex@xxxxxxxxxxx>
- Date: Sun, 15 Jan 2012 09:53:20 -0800
Pradeep Patra <smilesonisamal@xxxxxxxxx> wrote:
Hi all,
I want to merge more than 2 arrays.
For example:
@array1 = (1,2,3);
@array2 = (4,5,6);
@array3 = (7,8,9);
@array4 = (10,11,12);
my @array;
@array = (@array1,@array2,@array3,@array4);
print "Array elements:@array";
It works and displays 1-12. But I need something different because i
dont know the value of "n" beforehand.
Yes, you do know. Or how did you declare and define all those arrays
without knowing how many there are?
However, that is not the real the issue here. Whenever you find yourself
numbering your variables like above and on top of it you don't even know
how many variables you need, then you should seriously look into a
different data structure. In this case use an array, Luke! Or what do
you think those numbers are for?
So I decided to use a for loop.
And then the for loop will work perfectly fine.
jue
.
- References:
- Merging Multiple Array elements
- From: Pradeep Patra
- Merging Multiple Array elements
- Prev by Date: Re: problem reading html stream SOLVED
- Next by Date: Re: Merging Multiple Array elements
- Previous by thread: Merging Multiple Array elements
- Next by thread: Re: Merging Multiple Array elements
- Index(es):
Relevant Pages
|