在输入文件名中给出当前日期时perl脚本中的编译错误

时间:2012-07-31 06:14:37

标签: perl

根据以下脚本,尝试提供两个输入文件。 Test_DDD111_20120731.csv和DDD111.txt。 在一个文件夹中,将提供具有不同日期的Test_DDD111 * .csv文件。我想在此脚本中仅提供当前日期文件作为输入。

我将日期指定为$ deviationreportdate。但我收到错误,任何人都可以帮我解决这个问题。

我得到的错误:

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;
}

1 个答案:

答案 0 :(得分:1)

此正则表达式无效

$Test_file =~ /Test_DDD(\d+)/${deviationreportdate}*

在正则表达式中的最后一个斜杠后面只能有修饰符。我不确定你要用这个做什么,否则我会为你发布正确的正则表达式。也许你这么做了?

$Test_file =~ /Test_DDD(\d+)\/${deviationreportdate}*/

或者

$Test_file =~ /Test_DDD(\d+)${deviationreportdate}*/