in reply to mix arrays
I would initially put a mapping from @b to @a into a translation mapping hash:
my %b_a_map = map { (split / /)[0] => $_ } @a;And then generating @c becomes a simple O(n) loop:
my @c = map { $b_a_map{$_} } @b;@c will now look something like:
apple 2 apple 2 apple 2 orange 5 orange 5 pear 3
Edit: Output re-run with verbatim OP input, instead of my slightly modified test input.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: mix arrays
by AnomalousMonk (Archbishop) on Aug 07, 2013 at 18:04 UTC | |
by rjt (Curate) on Aug 07, 2013 at 18:28 UTC |