UPDATE - Wow. Sorry for not responding to all who responded here. I'm sorely tempted to copy a thank-you to each, but that smacks of spam and insincerity so I'm not sure I want to do this. Up-Votes were done, though, so your contributions were not ignored.

My one defense is that you gave me so much to think about and work through that I put in a lot more time than usual to work the concepts into my code :) Successfully, too. I love it when that happens.

Original text

I'm running through an array via foreach, and as it runs through the array I'd like to be able to delete rows based on specific content. I've found reference material showing how to do this with a hash, but not with an array.

Changing over to a hash would add to the complexity. I need to keep the rows in the same order as they are read in from the file, and don't otherwise need hash features for this data.

Is it possible to just delete the current row from an array when looping through it without setting up a counter and splice operation ? That's the only way I can see of accomplishing this, and I suspect this problem could be solved in a more concise way.

I can clear the row with a regex substitution, but this leaves a blank row in place and the dreaded uninitialized value warning rears up...
Dyslexics Untie !!!

In reply to foreach array - delete current row ? by JockoHelios

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.