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.
In reply to Re: mix arrays
by rjt
in thread mix arrays
by hulketa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |