I have a ternary operator that I would like to be rounded to the nearest tenth decimal place before the array is pushed.
For example: I would like the current output of my ternary operator: 2.44318181818182 to be rounded to 2.4. Below is what my code looks like: #!/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 = ( length( $dist ) > 1 ) ? $dist/6.6/8/2*10/10 : 0 ; ##### I would like to round the number to the nearest tenth right here. ######## $sum{$cell}{$sect}{$carr}{$dist} += $rlp1 += $rlp2 += $rlp3 += $rlp4 || 0 ; } #=~ m/^-?\d+$/) #my $marketInfo = ''; #if ($data[31] =~ m/^-?\d+$/) { #### regular expression for real numerical value # my $mkt = getMarket($data[31]); 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 $out "$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/