in reply to Can this code be optimized further?
I'd use:
If you expect to not have many matches, that is, most elements in @temp don't contain a_ or b_, I'd try to see whether the simpler regex is enough gain to have both the map and the grep:my @temp = (...); my @a = map {/a_(.*)/ ? $1 : ()} @temp; my @b = map {/b_(.*)/ ? $1 : ()} @temp;
my @a = map {/a_(.*)/; $1} grep /a_/ @temp; my @b = map {/b_(.*)/; $1} grep /b_/ @temp;
|
|---|