【发布时间】:2020-03-16 00:33:42
【问题描述】:
运行在同一目录中的文件列表上运行的 Perl 脚本会列出更改列表,它对我来说很好,但目前,我必须在 sun Solaris 10 上使用该脚本,但我收到了以下警告:
在 /usr/perl5/5.8.4/lib/sun4-solaris-64int/Convert/ASN1/_decode.pm 第 58 行使用未初始化的长度值。
在 /usr/perl5/5.8.4/lib/sun4-solaris-64int/Convert/ASN1/_encode.pm 第 60 行的连接 (.) 或字符串中使用未初始化的值。
在搜索之后我发现了一些东西说 use strict 和 use warnings 但是当我进行更改时它返回以下错误:
全局符号“@files”在 ./5th_edit.pl 处需要明确的包名称
第 14 行。全局符号“@dirs”需要在 ./5th_edit.pl 第 15 行。
#!/usr/bin/perl -w
use strict;
use warnings;
use TAP3::Tap3edit;
use Data::Dumper;
printDir(".");
sub printDir{
opendir(DIR, $_[0]);
local(@files);
local(@dirs);
(@files) = readdir(DIR);
foreach $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/^1299/
)
{
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);
}
【问题讨论】:
-
严格和警告的概念就是这样,它会告诉你问题在哪里以及究竟是什么行......所以在
use Data::Dumper;之后添加my @files;和my @Dirs;来声明它们和在此行中在$file之前添加myforeach my $file (@files) { -
谢谢亲爱的,还是一样,但现在我可以看到问题的确切位置,它返回
Argument "mobileOriginatedCall" isn't numeric in array element at ./5th_edit.pl line 72. -
这不是同一个问题。这意味着您的阵列存在问题。
标签: perl