in reply to Comparing 1 array that matches in 2nd array
Also, the way you have it written results in empty elements in your final array (or undef if you remove the quotes from around $theline). Take a look at this approach:
#!/usr/bin/env perl use strict; use warnings; use Data::Printer; my @pcov = qw( junk yphs.pc0.samelogic.fois_ebs.sbetrgt_inst nothing ) +; my @realassert = qw( stuff sbetrgt_inst other); my @thelist; foreach my $regex ( @realassert ) { push @thelist, grep{ /$regex/ } @pcov; } p @thelist;
|
|---|