
PERLonLINE
stranger
Sep 18, 2001, 3:48 AM
Post #1 of 4
(979 views)
|
|
Effeciently determining if a list is contained in
|
Can't Post
|
|
Hi Perl Gurus, this is my first post in this forum. So I may ask something that is in the FAQs or has been posted already a thousand times. But I'm a bit rushed because I have to accomplish a task with Perl right now. I have searched my available ressources (i.e. Perl's own POD, FAQ, the "Perl Cook Book" other ORA Books, posting in a German Perl forum). I would consider myself rather a Perl rookie, but I post here in the advanced section because I hope to find the gurus here. My task at hand is quite simple to describe. Let me give you two lines of a similar example: # fill list @a from lower to upper boundary # with some pseudo random numbers # (just to have something to play with ;-) ($lb, $ub) = (1, 100); @a = map int(rand($ub - $lb) + 1) + $lb), ($lb..$ub); # fill a 2nd, smaller list @b @b = map int(rand($ub - $lb) + 1) + $lb), ($lb..$ub/5); Now I would like, for instance, to find all the indices of array @a which hold values from array @b. To me this seems to call for some Schwartzian transform to do it most effeciently through some cleverly linked greps and maps. I think one would have to construct some interim anonymous array ref like "map { [$idx++, $_ ] } @a" to grep with through the values of @b, and map the result again into a new list. But I cannot find the trick. Of course, I could do it in ordinary foreach loops, but this doesn't seem to be very efficient.
|