in reply to Deleting elements of one list using another
use strict; use warnings; my @arr1 = ("John, ABC, 42","Jane, XYZ, 34","Jessica, GHI, 21"); my @arr2 = ("ABC", "XYZ"); my @arr3; my %seen; foreach my $arr1(@arr1) { my @splitted = split (/,/, $arr1); foreach my $arr2(@arr2) { if (grep(/$arr2/, @splitted)) { unless ($seen{$arr1} ){ push (@arr3, $arr1); } } } } for (@arr3) {print "$_\n";}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Deleting elements of one list using another
by Sj03rd (Initiate) on Aug 02, 2012 at 12:16 UTC | |
by nemesdani (Friar) on Aug 02, 2012 at 20:25 UTC |