Folks-

I actually have 2 questions:
1.) Is using map here the most efficient way to do this (for much larger lists)?
Update: I expect to run into memory problems when I start testing with a full dataset. ++ikegami thanks for the suggestion

2.) How can I get rid of the null list element in the result of the map example? The if statement doesn't seem to be working. I suspect I need some more help understanding how map works (I'm still trying to get my head around it).
Update: Thanks to all for the various suggestions:
++stiller - Thanks for the reminder that perl grep is useful here too, my mind hasn't yet been retreaded off of unix grep!
++andreas1234567 - Thanks for the first for loop suggestion. I should consider simple constructs, but map is just really cool.
++kyle - Nice explanation on what I was missing. Thanks teacher!
++Corion - I could use tr in this simplified example (my bad) the actual work needed isn't tr-able.

#!/opt/exp/bin/perl5.8 use strict; use warnings; use Data::Dumper; my @a = ( qw (onexxx txwxo txhrexe xfourx xxx five) ); my @b = map { $_ =~ s/x//g; $_ if ($_); } @a; print Dumper(\@b);

In reply to Basic list manipulation, and a bit of map() confusion... by cmv

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.