As per below script, Trying to give two Input files. Test_DDD111_20120731.csv and DDD111.txt.
Inside one folder this Test_DDD111*.csv file with different date will be available. I want to give only current date file as input inside this script.
I assign date as $deviationreportdate. But i am getting error, can anyone help me to solve this problem.
Error which i am getting:
Scalar found where operator expected at subscriberdump.pl line 58, near "/Test_DDD(\d+)/${deviationreportdate}"
(Missing operator before ${deviationreportdate}?)
syntax error at subscriberdump.pl line 58, near "/Test_DDD(\d+)/${deviationreportdate}"
Execution of test.pl aborted due to compilation errors.
#!/usr/bin/perl
use strict;
use warnings;
use strict;
use POSIX;
my @array123;
my $daysbefore;
my %month="";
my ($f2_field, @patterns, %patts, $f2_rec);
while (@ARGV)
{
my $par=shift;
if( $par eq "-d" )
{
$daysbefore=shift;
next;
}
}
sub getDate
{
my $daysago=shift;
$daysago=0 unless ($daysago);
my @months=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
Localtime(time(86400*$daysago));
# YYYYMMDD, e.g. 20060126
return sprintf("%d%02d%02d",$year+1900,$mon+1,$mday);
}
my $deviationreportdate=getDate($daysbefore-1);
my $transactiondate=getDate($daysbefore);
my $filename="output.txt");
open(OUTPUTFILE,"> /tmp/$filename");
for my $Test_file (<Test_DDD*${deviationreportdate}*>)
{
if ($Test_file =~ /Test_DDD(\d+)/${deviationreportdate}*)
{
my $file = "DDD$1.txt";
my $ID="DDD$1";
open AIN, "<$file" or die($file);
open BIN, "<$Test_file" or die($Test_file);
my %seen;
}
This regular expression is invalid
$Test_file =~ /Test_DDD(\d+)/${deviationreportdate}*you can only have modifiers after the last slash in a regex. I’m not exactly sure what you’re trying to do with this, otherwise I would post the correct regex for you. maybe you ment this?
$Test_file =~ /Test_DDD(\d+)\/${deviationreportdate}*/or this
$Test_file =~ /Test_DDD(\d+)${deviationreportdate}*/