in reply to Basic list manipulation, and a bit of map() confusion...

Is using map here the most efficient way to do this (for much larger lists)?

What kind of problem are you having? Speed? memory? something else?

If you want to reduce your memory footprint, you could use a counting loop and push.

for my $i (0..$#a) { my $s = $a[$i]; $s =~ s/x//g; push @b, $s if $s; }

As for the speed difference between this and your solution, only a benchmark will tell. Should be very similar.

Replies are listed 'Best First'.
Re^2: Basic list manipulation, and a bit of map() confusion...
by ysth (Canon) on Feb 24, 2008 at 19:37 UTC
    "for" over an array is optimized; this works just as well from a memory perspective:
    for my $a_val (@a) { (my $s = $a_val) =~ s/x//g; push @b, $s if $s; }
      Thanks. I suspected as much — I already realized naught-but-an-array was special — but I didn't have time to check it when I posted the grandparent.