Hello,
I am trying to write a Perl script that searches through a directory on Windows and returns the file names matching a pattern that's stored in a scalar variable. Please find my code below:
use warnings;
use strict;
use Data::Dumper;
use MIME::Lite;
my @fields;
my @files;
my $dir="places";
sub _processfile()
{
my %places=();
open(FH,"<","ms.csv") or die "Can't open file: $!\n";
opendir(my $dh, $dir) or die "Can't open dir: $!\n";
while(my $line = <FH>)
{
chomp($line);
@fields = split(/\,/,$line);
$places{$fields[0]}=$fields[1];
}
closedir $dh;
close(FH);
}
_processfile();
The file contains the names of buildings and the second column contains information about that building. I want to read through the file, grab the building name and search a directory for files that contain the building name. All the files are of PDF format and contain the name of the building within the name.
Data example:
Building1,Data1;Data2
Building2,Data3;Data4
I have tried to use grep to make this happen, but it doesn't work when the pattern in a variable. If I use an explicit pattern rather than a variable, it returns correctly. Please assist!
Thanks!