Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: mix arrays

by 2teez (Priest)
on Aug 07, 2013 at 17:07 UTC ( #1048384=note: print w/ replies, xml ) Need Help??


in reply to mix arrays

You can do this:

use Data::Dumper; my @a_array = ('apple 2', 'orange 5', 'pear 3',); my @b_array = ('apple', 'apple', 'apple', 'orange', 'orange', 'pear', +); my @c_array; for my $item_1 (@b_array){ for my $item_2 (@a_array){ push @c_array, $item_2 if $item_2=~/^$item_1/; } } print Dumper \@c_array;
Produces ...
$VAR1 = [ 'apple 2', 'apple 2', 'apple 2', 'orange 5', 'orange 5', 'pear 3' ];

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: mix arrays
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048384]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-08-29 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls