coldy has asked for the wisdom of the Perl Monks concerning the following question:
so for example, the first elements of each array (1 and 5) represent the numbers 1,2,3,4,5; the two arrays define the numbers 1,2,3,..5,15,16,..,20,...,65,66,...,77) Now, I also have two scalars, say, $s1=9, $s2=35, where these also represent a range of integers 9,10,11,..,35. The problem is to find the numbers defined by @a and @b which intersect with the range defined by $s1 and $s2.@a=(1,15,30,50,65) @b=(5,20,37,55,77)
I tend to things the long way in perl, so I thought of creating an array of arrays
then finding the intersection of ($s1..$s2) with each of the array elements.@AoA=([1,5],[15,20],...,[65,77]) <p>
If anybody can think of a better way to do this, any help much appreciated, otherwise, a good way to create the array of array would also be appreciated.
Thanks in advance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: array of arrays or not
by BrowserUk (Patriarch) on Feb 23, 2009 at 07:21 UTC | |
|
Re: array of arrays or not
by ysth (Canon) on Feb 23, 2009 at 07:45 UTC | |
|
Re: array of arrays or not
by tilly (Archbishop) on Feb 23, 2009 at 07:57 UTC | |
|
Re: array of arrays or not
by CountZero (Bishop) on Feb 23, 2009 at 09:51 UTC | |
|
Re: array of arrays or not
by poolpi (Hermit) on Feb 23, 2009 at 10:51 UTC |