0
votes

running Perl script that run over the list of files in the same directory do list of changes and its worked for me fine, but currently, I have to use the script on sun Solaris 10, but I'm getting these warnings :

Use of uninitialized value in length at /usr/perl5/5.8.4/lib/sun4-solaris-64int/Convert/ASN1/_decode.pm line 58.

Use of uninitialized value in concatenation (.) or string at /usr/perl5/5.8.4/lib/sun4-solaris-64int/Convert/ASN1/_encode.pm line 60.

and after searching I have found something say use strict and use warnings but when i made the changes it returns the below errors :

Global symbol "@files" requires explicit package name at ./5th_edit.pl

line 14. Global symbol "@dirs" requires explicit package name at ./5th_edit.pl line 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);
}
1
The idea of strict and warnings is exactly that, it tells you where your issues are and exactly what lines... so add my @files; and my @Dirs; just after use Data::Dumper; to declare them and add my before $file in this line foreach my $file (@files) { - Gerhard
thank you dear, stil same thing but now i can see where the issues exactly , it returns Argument "mobileOriginatedCall" isn't numeric in array element at ./5th_edit.pl line 72. - yong shi
That is not quite the same issue. That means there is issues with your array. - Gerhard

1 Answers

1
votes

Initialise the @files and @dirs variables with my instead of local.

my @files;
my @dirs;

What is the difference between my and local in Perl?