Using size of array instead of last idx
When looping over the array using the size of the array rather
than the last index. Using the last index can create issues in
some cases (there are no decomposition files in the directory).
@@ -24,19 +24,20 @@ sub rem_dup_decomp_files
my @decompfile_info_tmp = map{ {FNAME=>$_, SIZE=>-s $_, IS_DUP=>0} } grep(/${PIO_DECOMP_FNAMES}/,readdir(F));
closedir(F);
my @decompfile_info = sort { $a->{SIZE} <=> $b->{SIZE} } @decompfile_info_tmp;
+ my $ndecompfile_info = @decompfile_info;
- #for(my $i=0; $i<=$#decompfile_info; $i++){
+ #for(my $i=0; $i<$ndecompfile_info; $i++){
# print "File : $decompfile_info[$i]->{FNAME} , size = $decompfile_info[$i]->{SIZE}\n";
#}
my $rmfile=0;
# Compare the decomposition files to find
# duplicates - and delete the dups
- for(my $i=0; $i<=$#decompfile_info; $i++){
+ for(my $i=0; $i<$ndecompfile_info; $i++){
my $file = $decompfile_info[$i]->{FNAME};
my $fsize = $decompfile_info[$i]->{SIZE};
next if($decompfile_info[$i]->{IS_DUP});
- for(my $j=$i+1;$j<=$#decompfile_info;$j++){
+ for(my $j=$i+1;$j<$ndecompfile_info;$j++){
my $nfile = $decompfile_info[$j]->{FNAME};
my $f2size = $decompfile_info[$j]->{SIZE};
next if($decompfile_info[$j]->{IS_DUP});
@@ -77,7 +78,7 @@ sub rem_dup_decomp_files
}
}
}
- for(my $i=0; $i<=$#decompfile_info; $i++){
+ for(my $i=0; $i<$ndecompfile_info; $i++){
if($decompfile_info[$i]->{IS_DUP}){
unlink($decompfile_info[$i]->{FNAME});
}
@@ -95,7 +96,8 @@ sub decode_stack_traces
opendir(F,$dirname);
my @decompfiles = grep(/${PIO_DECOMP_FNAMES}/,readdir(F));
closedir(F);
- for(my $i=0; $i<= $#decompfiles; $i++){
+ my $ndecompfiles = @decompfiles;
+ for(my $i=0; $i< $ndecompfiles; $i++){
my $file = $decompfiles[$i];
open(F1,$file);
my @file1 = <F1>;
