Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048384]
[Discipulus]: but there is some perl workshop somewhere? I notice many high level monks disappeared.. we can make PM a squat in the meantime ;=)
[karlgoethebier]: Discipulus: Mmh, who disappeared?
[marto]: morning all
[shmem]: perl -lE '$_="odd mornin";($o=$_)=~ s/^|$/g/g;say$o'
[Eily]: Hi monks o/
[choroba]: 3 PM in Vietnam, BTW
Discipulus maybe a wrong impression..

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2017-06-27 08:08 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (600 votes). Check out past polls.