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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |