corfuitl has asked for the wisdom of the Perl Monks concerning the following question:
Hi all
I have two arrays (arr1 and arr2) and I would like to split them into chunks based on a third, 2d array.
The 2d array contains the values below, which correspond to arr positions. For instance,
Arr1 Arr2 3 4 5 5 6 6 8 10
I want to create files that contain the arr1 and arr2 contents. For instance:
File-arr1-1.txt arr1[0], arr1[1], arr1[2] File-arr2-1.txt arr2[0], arr2[1], arr2[2], arr2[3] File-arr1-2.txt arr1[3] File-arr2-2.txt arr2[4] File-arr1-3.txt arr1[4] File-arr2-3.txt --- File-arr1-4.txt arr1[5] File-arr2-4.txt arr2[5] File-arr1-5.txt arr1[6] File-arr2-5.txt arr2[6] File-arr1-6.txt arr1[7] File-arr2-6.txt arr2[7], arr2[8], arr2[9] File-arr1-7.txt arr1[8] File-arr2-8.txt arr2[10]
So... all in all... I want in separate files the difference and in separate files the contents of the 2d array.
Here is a piece of my code but it doesn't work
my $start = 0; my $end = 0; for my $i (0 .. $#al) { $end = $al[$i][0]; for my $s ($start .. $end-1){ print "$start\t$end\n"; if ($s == $end-1){ $start = $end+1; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: splitting 2D array into chunks
by shmem (Chancellor) on Jun 21, 2021 at 18:46 UTC | |
|
Re: splitting 2D array into chunks
by BillKSmith (Monsignor) on Jun 21, 2021 at 20:21 UTC | |
|
Re: splitting 2D array into chunks
by AnomalousMonk (Archbishop) on Jun 21, 2021 at 20:34 UTC |