There is one more way to deal with the splicing problem: run through the array backwards. It sounds wierd, but it does work. If you build up a list of the indexes that you want to splice out, process it in reverse (using pop), and then splice, the indices won't change (because the array is shrinking from the end), and everything is fine. I just so happened to get bitten by something similar.

Consider the following (untested) snippet:
my $splice_index = 0; my @splice_list; for (@clean) { if (length($_) == 0) { #zero - length string push(@splice_list,$splice_index); $splice_index++; next; } $splice_index++; } #now we have our splice list built up. so, we take care of the element +s that need to go. while (@splice_list) { my $index = pop(@splice_list); splice(@clean,$index,1); } print "$_\n" for @clean; #should produce the correct results @clean = map {s/\s+//g; $_ } @clean; #i try to avoid map in void conte +xt, except for in my sig ^_~ print "$_\t" for @clean; print "\n";
I actually used something like this in a module I'm writing. I hope it's of some use to you. YMMV.

Theodore Charles III
Network Administrator
Los Angeles Senior High
email->secon_kun@hotmail.com
perl -e "map{print++$_}split//,Mdbnr;"

In reply to Re: Array Cleaning by Necos
in thread Array Cleaning 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.