Dear Monks, I have two arrays that look like this:

@array1= 1 83 90 120 140 300

@array2= 83 140

I want to delete all the values in array2 out of array1 so array 1 looks like this:

@array1= 1 90 120 300

I have tried using for loops to iterate through the arrays:

for (my $search =0; $search<scalar @array1; $search++) { for ($search2 =0; $search2<scalar @array2; $search2++) { if($array1[$search] eq $array[$search2]) { this is where I want to do something that deletes the appr +opriate value from array1 } else { carry on as usual, no deletions }
I tried using undef to delete, and I know unshift/shift/pop/push only work at the start and end of arrays.

Any suggestions, Thanks


In reply to subtract one array from another by Anonymous Monk

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.