Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2016-02-07 11:02 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (250 votes), past polls