在perl的数组元素中不是数字

时间:2019-11-20 11:53:36

标签: perl

im正在运行的脚本,该脚本处理同一目录中的文件列表以对这些文件进行一些更改,然后代码可以正常工作,但是在我添加了use strictuse warnings之后,它返回了以下问题:

  

./ 5th_edit.pl第72行的数组元素中的参数“ mobileOriginatedCall”不是数字。

     

./ 5th_edit.pl第96行的数组元素中的参数“ gprsCall”不是数字。

#!/usr/bin/perl -w

use strict;
use warnings;

use TAP3::Tap3edit;
use Data::Dumper;



printDir(".");
sub printDir{
opendir(DIR, $_[0]);
my @files;
my @dirs;
 (@files) = readdir(DIR);
 foreach my $file (@files) {
    if (-f $file and substr($file,0,2) eq "CD" ) {


     my $tap3 = TAP3::Tap3edit->new;

     my $tap_file = $file;
$tap3->decode($tap_file)  or  die $tap3->error; 

my $struct=$tap3->structure;
my $Tracker = $struct->{'transferBatch'};
if (defined $Tracker){

    my $rectag = $struct->{'transferBatch'}->{'networkInfo'}->{'recEntityInfo'};

    map { $_->{'recEntityType'} = 4 if ( $_->{'recEntityType'} > 6) } @$rectag;

    my $calleventtag = $struct->{'transferBatch'}->{'callEventDetails'};

    my @indexes = reverse (grep { exists $calleventtag->[$_]->{'supplServiceEvent'} } 0..$#$calleventtag);

    my $sup_event_cnt = $#indexes;

    foreach my $index (@indexes)
    {
    splice (@$calleventtag , $index,1);
    }

    my $total_events_cnt = $struct->{'transferBatch'}->{'auditControlInfo'}->{'callEventDetailsCount'};
    $struct->{'transferBatch'}->{'auditControlInfo'}->{'callEventDetailsCount'} = $total_events_cnt - $sup_event_cnt-1;

    if ( exists $struct->{'transferBatch'}->{'batchControlInfo'}->{'operatorSpecInformation'} )
        {
            delete $struct->{'transferBatch'}->{'batchControlInfo'}->{'operatorSpecInformation'};
        }
    if ( exists $struct->{'transferBatch'}->{'auditControlInfo'}->{'operatorSpecInformation'} )
        {
            delete $struct->{'transferBatch'}->{'auditControlInfo'}->{'operatorSpecInformation'};
        }

my $key;

# Will scan all the calls for MOC's and GPRS.
foreach $key ( @{$struct->{'transferBatch'}->{'callEventDetails'} } ) {

    foreach ( keys %{$key} ) {

        if ( $_ eq "mobileOriginatedCall" )
        {

            if ( exists $calleventtag->[$_]->{'mobileOriginatedCall'}->{'basicCallInformation'}->{'destinationNetwork'} )
            {
                delete $calleventtag->[$_]->{'mobileOriginatedCall'}->{'basicCallInformation'}->{'destinationNetwork'};
            }

            if ( exists $calleventtag->[$_]->{'mobileOriginatedCall'}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'} 
            && $calleventtag->[$_]->{'mobileOriginatedCall'}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'} !~ m/^96279/ 
            )
            {
                delete $calleventtag->[$_]->{'mobileOriginatedCall'}->{'basicCallInformation'}->{'chargeableSubscriber'}->{'simChargeableSubscriber'}->{'msisdn'};
            }

            if ( exists $calleventtag->[$_]->{'mobileOriginatedCall'}->{'camelServiceUsed'}  
            && $calleventtag->[$_]->{'mobileOriginatedCall'}->{'camelServiceUsed'}->{'camelServiceKey'} != 80
            )
            {
                delete $calleventtag->[$_]->{'mobileOriginatedCall'}->{'camelServiceUsed'};
            }

        }

        if ( $_ eq "gprsCall" )
        {

            if ( exists $calleventtag->[$_]->{'gprsCall'}->{'gprsBasicCallInformation'}->{'gprsDestination'}->{'accessPointNameOI'} )
            {
                delete $calleventtag->[$_]->{'gprsCall'}->{'gprsBasicCallInformation'}->{'gprsDestination'}->{'accessPointNameOI'};
            }

        }

    }
}


    $tap3->encode("$tap_file")  or  die $tap3->error; 
}    

    }

 } 

 closedir(DIR);
}

我认为这部分有问题:

if ( $_ eq "mobileOriginatedCall" )

if ( $_ eq "gprsCall" )

这些文件的每个文件如下所示,但调用次数不同:

跟踪堆栈:

Argument "gprsCall" isn't numeric in array element at ./5th_edit.pl line 96.
Argument "gprsCall" isn't numeric in array element at ./5th_edit.pl line 96.
Argument "gprsCall" isn't numeric in array element at ./5th_edit.pl line 96.
Argument "gprsCall" isn't numeric in array element at ./5th_edit.pl line 96.
Argument "gprsCall" isn't numeric in array element at ./5th_edit.pl line 96.
Argument "mobileOriginatedCall" isn't numeric in array element at ./5th_edit.pl line 72.
Argument "gprsCall" isn't numeric in array element at ./5th_edit.pl line 96.
Argument "gprsCall" isn't numeric in array element at ./5th_edit.pl line 96.
Argument "gprsCall" isn't numeric in array element at ./5th_edit.pl line 96.
Argument "gprsCall" isn't numeric in array element at ./5th_edit.pl line 96.
Argument "gprsCall" isn't numeric in array element at ./5th_edit.pl line 96.
Use of uninitialized value in concatenation (.) or string at /usr/perl5/5.8.4/lib/sun4-solaris-64int/Convert/ASN1/_encode.pm line 60.
Use of uninitialized value in concatenation (.) or string at /usr/perl5/5.8.4/lib/sun4-solaris-64int/Convert/ASN1/_encode.pm line 60.
Use of uninitialized value in concatenation (.) or string at /usr/perl5/5.8.4/lib/sun4-solaris-64int/Convert/ASN1/_encode.pm line 60.
Use of uninitialized value in concatenation (.) or string at /usr/perl5/5.8.4/lib/sun4-solaris-64int/Convert/ASN1/_encode.pm line 60.
Use of uninitialized value in concatenation (.) or string at /usr/perl5/5.8.4/lib/sun4-solaris-64int/Convert/ASN1/_encode.pm line 60.
Use of uninitialized value in concatenation (.) or string at /usr/perl5/5.8.4/lib/sun4-solaris-64int/Convert/ASN1/_encode.pm line 60.
Use of uninitialized value in concatenation (.) or string at /usr/perl5/5.8.4/lib/sun4-solaris-64int/Convert/ASN1/_encode.pm line 60.
Use of uninitialized value in concatenation (.) or string at /usr/perl5/5.8.4/lib/sun4-solaris-64int/Convert/ASN1/_encode.pm line 60.

1 个答案:

答案 0 :(得分:2)

你有

if ( $_ eq "mobileOriginatedCall" ) {
   if ( exists $calleventtag->[$_]->...

等同于

if ( $_ eq "mobileOriginatedCall" ) {
   if ( exists $calleventtag->["mobileOriginatedCall"]->...

这意味着您试图获取mobileOriginatedCall引用的数组的元素编号$calleventtag,这没有任何意义; mobileOriginatedCall不是数字。