grep a scalar from an array in Perl
I've searched the web for solution but could not find it. I'm hoping you guys can suggest something.
I have the following data in a file:
...
...
XNYS|11/23/2017|Thanksgiving|A|
XNYS|11/24/2017|Day After Thanksgiving|P|218,219
XNYS|12/24/2017|Day before Christmas|P|218,219
XNYS|12/25/2017|Christmas|A|
XNYS|04/24/2017|Kemal Day|A|
XNYS|04242017|My Day1|A|
XNYS|04252017|Day 25|A|
I initialized the following in a perl script:
my $Today = `date +%m%d%Y`;
my $Holidayfile = '/tmp/perl/DoNotHolidaylist.txt';
my @verify;
my $fandler;
Then I open the file and then load its contents to an array. I then try to print out if there's a matching data.
open($fandler, "$Holidayfile") || die "[ERROR] Opening file $!";
my @list = <$fandler>;
close $fandler;
#@verify = grep /XNYS.*${Today}/, @list;
@verify = grep /XNYS/, @list;
@verify = grep /$(Today)/, @verify;
print "Today is a holiday: @verify\n";
I'm expecting the print out to be:
"Today is a holiday: XNYS|04252017|Day 25|A|"
However, regardless of what combo I tried with "{}" around "Today" or "()" around "Today" I just cannot get my expected line to be printed out.
If I replace the last line for @verify with the following, I do see what I expect so that leads me to believe, "$Today" is not be parsed as I expect it to be:
@verify = grep /04252017/, @verify;
Can someone help out?
Thanks
|