2012/1/15 Pradeep Patra <smilesonisa...@gmail.com> > I want to merge more than 2 arrays.
@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. What do you mean by 'n'? Size of the final array? It's { scalar @final_array }, yes, that simple. ) Number of arrays to merge? Well, I guess they should be stored somewhere anyhow. ) And if they're stored in some collection, like... *my @collection_of_arrays = (* * [1, 2, 3],* * [4, 5, 6],* * [7, 8, 9] * *)* ... then again the number is the size of this collection. And it's pretty easy to flatten this @collection, like this: *my @flattened_collection = map { @$_ } @collection_of_arrays;* * * You'd like to store arrays as separate variables instead - but don't know their number at 'compilation' time? ) And this is practical task? ) Yes, this can be solved with soft references one way or another (*@result_array = map { eval { '@array'.$_ } } 1..n*), but why you might ever need this, is beyond me. ) * * -- iD