rsiedl has asked for the wisdom of the Perl Monks concerning the following question:
How would I go about matching which items in each array could match?@array1 = [ "test", "test2", "test2", "test3", "test4", "test4" ]; @array2 = [ "test", "test", "test2.1", "test4.1", "test4.2", "test4.3" + ];
To get the result:foreach my $item (sort @array1) { foreach my $found (@array2) { if (&match_names($item,$found)) { print "found a match ($item = $found\n"; push(@save, $found); } # end-if } # end-foreach } # end-foreach foreach my $item (sort @array2) { foreach my $found (@array1) { if (&match_names($item,$found)) { print "found a match ($item = $found\n"; push(@save, $found); } # end-if } # end-foreach } # end-foreach sub match_names { # i have this part, its just a simple regex # BUT this must only match in "one direction": test4 matches test 4. +1, but test4.1 doesnt match test4 return 1 if ($x =~ /some_regex_on_$y/); }
because test appears in both arrays once,@save contains [ "test", "test2", "test4", "test4" ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: multiple matching in arrays
by liverpole (Monsignor) on Aug 01, 2006 at 11:37 UTC | |
|
Re: multiple matching in arrays
by rodion (Chaplain) on Aug 01, 2006 at 12:14 UTC | |
|
Re: multiple matching in arrays
by imp (Priest) on Aug 01, 2006 at 12:59 UTC | |
|
Re: multiple matching in arrays
by Moron (Curate) on Aug 01, 2006 at 11:18 UTC | |
|
Re: multiple matching in arrays
by johngg (Canon) on Aug 01, 2006 at 15:30 UTC | |
|
Re: multiple matching in arrays
by Mandrake (Chaplain) on Aug 01, 2006 at 13:32 UTC |