hulketa has asked for the wisdom of the Perl Monks concerning the following question:
Hi perlmonkers, your help other times have benn so useful so here I go with another problem: I have two arrays like these: @a = apple 2, orange 5, pear 3... @b = apple, apple, apple, orange, orange, pear... So, I need to get a new array (@c) with @a items , but repeated so many time as they are repeated in @b. Like this: @c = apple 2, apple 2, apple 2, orange 5, orange 5, pear 3... so, I've tried something like this:
foreach (@b){ for $item (@a){ push(@c, $item) if grep {$item =~ m/$_/} @b;}} print "@c";
But it doesn't work, and it don't give me any error. It just don't run. If someone can help me I'd thanks so much! I'm obfuscate right now! Thanks guys!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: mix arrays
by 2teez (Vicar) on Aug 07, 2013 at 17:07 UTC | |
|
Re: mix arrays
by AnomalousMonk (Archbishop) on Aug 07, 2013 at 17:59 UTC | |
|
Re: mix arrays
by McA (Priest) on Aug 07, 2013 at 17:00 UTC | |
|
Re: mix arrays
by rjt (Curate) on Aug 07, 2013 at 16:57 UTC | |
by AnomalousMonk (Archbishop) on Aug 07, 2013 at 18:04 UTC | |
by rjt (Curate) on Aug 07, 2013 at 18:28 UTC |