in reply to mix arrays
Hi
my approach, as I don't know which rules are followed by the names 'orange 5':
use strict; use warnings; use 5.010; my @a = ('apple 2', 'orange 5', 'pear 3'); my @b = qw/apple apple apple orange orange pear apple orange orange/; my %a; my @c; foreach my $fruit (@b) { if(exists $a{$fruit}) { push @c, $a{$fruit}; next; } my ($hit) = grep { $_ =~ /$fruit/ } @a; push @c, $hit; $a{$fruit} = $hit; } say join "\n", @c;
Best regards
McA
|
|---|