-1

以下のスクリプトに従って、2 つの入力ファイルを指定しようとしています。Test_DDD111_20120731.csv および DDD111.txt。1 つのフォルダー内で、異なる日付のこの 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 に答える