-1

根据以下脚本,尝试提供两个输入文件。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;
}
4

1 回答 1

1

此正则表达式无效

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

您只能在正则表达式的最后一个斜杠之后使用修饰符。我不确定您要对此做什么,否则我会为您发布正确的正则表达式。也许你提到这个?

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

或这个

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

于 2012-07-31T06:32:26.880 回答