cstrong has asked for the wisdom of the Perl Monks concerning the following question:
I'm only a Perl beginner and I know there are lots and lots of pages out there that deal with searching through arrays, but I cannot find anything relevant to my problem.
I have two arrays and I want to find if one of the arrays is contained within the other (with the order preserved). Moreover I want to then be able to delete the contents of one array from the other
@bigarray qw(this is the main array from which to delete elements) @smallarray qw(delete elements)An array such as @other qw(elements delete) should not match against @bigarray.
I need to somehow remove "delete elements" from @bigarray. I have tried using nested loops, trying to keep track of indexs so I can use splice, but I just can't figure out how to do it properly with loops
@bigarray will probably be <1K in size and this delete action will only be called perhaps once or twice during my script, so efficiency is not an issue.
Any help appreciated :-)
Just for clarity, the exact sequence from @smallarray should be removed from @bigarray i.e.
@bigarray qw(delete this is elements the main array from which to delete elements)should be transformed to
@bigarray qw(delete this is elements the main array from which to)Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Check if one array is a subset of another
by tobyink (Canon) on Jan 04, 2012 at 17:06 UTC | |
by cstrong (Beadle) on Jan 04, 2012 at 17:18 UTC | |
|
Re: Check if one array is a subset of another
by BrowserUk (Patriarch) on Jan 04, 2012 at 17:08 UTC | |
|
Re: Check if one array is a subset of another
by Anonymous Monk on Jan 04, 2012 at 17:18 UTC | |
|
Re: Check if one array is a subset of another
by Khen1950fx (Canon) on Jan 04, 2012 at 17:52 UTC | |
|
Re: Check if one array is a subset of another
by choroba (Cardinal) on Jan 04, 2012 at 17:00 UTC | |
by cstrong (Beadle) on Jan 04, 2012 at 17:16 UTC |