Perl Monks,
I am trying to use an array to list regex search choices. Code works if a single regex is inputted.
use strict;
use warnings;
sub main
{
my @patterns = ("^abd", "ghi");
my $file = 'C:\Perl64\bin\hello.txt';
open(FH, $file) or die("File $file not found");
while(my $String = <FH>)
{
# if($String = ~ /^abd /)
if($String .= join ('/ && /', @patterns);
{
print "$String \n";
}
}
close(FH);
}
main();
Error:
Global symbol "@patterns" requires explicit package name at pattern2.pl line 7.
Global symbol "@patterns" requires explicit package name at pattern2.pl line 14.
syntax error at pattern2.pl line 14, near ");"
Execution of pattern2.pl aborted due to compilation errors.
What syntax error am I making?
Best,
David