Additionally, why use ls?
opendir(my $dh, '.')
or die("Unable to list directory: $!\n");
my @searchlist = readdir($dh);
or
opendir(my $dh, '.')
or die("Unable to list directory: $!\n");
while (defined(my $file = readdir($dh))) {
...
}
Combined with sachmet's solution:
opendir(my $dh, '.')
or die("Unable to list directory: $!\n");
my @patterns = map { qr/\Q$_\E/ }
grep { /^\.\.?$/ }
readdir($dh);
open(my $fh_in, 'test.txt')
or die("Unable to open input file test.txt: $!\n");
while (my $line = <$fh_in>) {
chomp $line;
foreach my $pattern (@patterns) {
print("Match found\n") if $line =~ $pattern;
}
}
Combined with holli's solution:
opendir(my $dh, '.')
or die("Unable to list directory: $!\n");
my %searchlist = map { $_ => 1 }
grep { /^\.\.?$/ }
readdir($dh);
open(my $fh_in, 'test.txt')
or die("Unable to open input file test.txt: $!\n");
while (my $line = <$fh_in>) {
chomp $line;
print("Match found\n") if $searchlist{$line};
}
Update: Fixed copy & paste error map { qr/\Q$pattern\E/ } => map { qr/\Q$_\E/ }. |