Jim, I am getting really close to finishing up this program. perl is lot's of fun and I appreciate all your help!
The output is giving me the data I am looking for except for the following issues: How would I add the correct code to make sure the array has a numeric value before the loop iterations begin? I am getting the following error multiple times and when I look at the output there are blanks. How can I eliminate this? Argument "" isn't numeric in addition (+) at ./DOband.pl line 30, <$fh> line 3. Thank you in advance. My complete program is posted at the bottom. >> >> $sum{$cell}{$sect}{$carr} += $rlp1 += $rlp2 += $rlp3 += $rlp4 || 0 ; } >> > If you want to accumulate the four variables, why not just do: > > $sum{$cell}{$sect}{$carr} += ($rlp1 + $rlp2 + $rlp3 + $rlp4) || 0 ; > I changed my code to your suggestion. The output is the same, but yours is much cleaner so I kept yours. Thank you. #!/usr/bin/perl use warnings; use strict; my $filepath = 'C:/temp/PCMD'; #my $filepath = '/home/cstinemetz/perl_programs/1.EVDOPCMD'; #my $outfile = 'output.txt'; open my $fh, '<', $filepath or die "ERROR opening $filepath: $!"; #open my $out, '>', $outfile or die "ERROR opening $outfile: $!"; my %sum; while (<$fh>){ next unless /;/; chomp; my @data = split /;/; my($cell,$sect,$chan,$carr,$rlp1,$rlp2,$rlp3,$rlp4,$dist,$precis) = @data[31,32,38,39,44,45,46,47,261,262]; $carr = ( $cell < 299 && $chan == 175 ) ? 2 : ( $chan == 1025 ) ? 2 : 1 ; #nested ternary operator $dist = sprintf "%.1f", ( length( $dist ) > 1 ) ? $dist/6.6/8/2*10/10 : 0 ; $sum{$cell}{$sect}{$carr}{$dist} += ($rlp1 + $rlp2 + $rlp3 + $rlp4) || 0 ; } my @data; for my $cell ( sort keys %sum ) { for my $sect ( sort keys %{$sum{$cell}} ) { for my $carr ( sort keys %{$sum{$cell}{$sect}} ) { for my $dist ( sort keys %{$sum{$cell}{$sect}{$carr}} ) { push( @data, [ $sum{$cell}{$sect}{$carr}{$dist}, $cell, $sect, $carr, $dist,]); } } } } for my $record ( sort { $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] || $a->[3] <=> $b->[3] || $a->[4] <=> $b->[4] } @data ) { my( $val, $cell, $sect, $carr, $dist ) = @$record; print "$cell\t $sect\t $carr\t $dist\t $val\n"; } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/