yong shi
yong shi

Reputation: 65

getting list error with using strict and warnings

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);
}

Upvotes: 0

Views: 114

Answers (1)

user1717259
user1717259

Reputation: 2863

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?

Upvotes: 1

Related Questions