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!


In reply to Check if one array is a subset of another by cstrong

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.