Re: Merging Multiple Array elements



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
.



Relevant Pages

  • Re: Whats the best language to learn...
    ... over the arrays of vertices, ... loop over the selected models; ... recently my edge construction and shadow-volume rendering code ... but enums just make it easier and quicker to make ...
    (comp.programming)
  • Re: awk and arrays
    ... Bearing in mind I'm very rusty with scripting -- data structures are part of ... going to loop over it many times? ... Or if they (the regulars) enjoy the problem and start playing golf with it, ... but not a way to loop on a subset of such multi-dimensional arrays. ...
    (comp.lang.awk)
  • Re: Segmentation fault (core dumped)
    ... I have two files from where I extract values in columns (1D dynamic arrays). ... IF (fInputStatus11 /= 0) EXIT ... Note that this READ is inside the J loop, and so will read the whole ...
    (comp.lang.fortran)
  • Re: GNAT compiler switches and optimization
    ... allocating and freeing arrays, the the effects ... But I imagined allocation is just what is happening all the time ... type LIST is array of BOOLEAN; ... 2000 loop ...
    (comp.lang.ada)
  • Re: Non-rectangular 3D plot
    ... Ok I see where my code would get very confusing now. ... I originally had it accepting arrays for my inputs, ... I have shown my new code below without x and y in the for loop. ... to have y increment over a counter j for a given x value. ...
    (comp.soft-sys.matlab)