>
> In the statement:
>
> if( $cell )
>
> $cell is evaluated for true or false. All scalar values are valid in this
> evaluation, including numerical, string, and undef, the three types of Perl
> scalar values.
>
> On the other hand, in this statement:
>
> if( $cell >= 1 && $cell <= 900 ) { ... }
>
I am getting a runtime error when I use the above if statement. My
goal is to only evaluate the $cell element which contain
the numerical value 1 through 900. Below is my error I am getting and
my program.
syntax error at ./DOband.pl line 22, near "{ ..."
Execution of ./DOband.pl aborted due to compilation errors.
#!/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,$rlp1,$rlp2,$rlp3,$rlp4,$dist) =
@data[31,32,38,44,45,46,47,261];
if( $cell >= 1 && $cell <= 900 ) { ... } ### This is where I am
getting my runtime error
my $carr =
( $cell <= 299 && $chan == 175 ) ? 2 :
( $cell >= 300 && $cell <= 599 && $chan == 75 ) ? 2 :
( $chan == 1025 ) ? 2 : 1
; #nested
ternary operator
$dist = sprintf "%.1f",
( length( $dist ) > 1 ) ? $dist/6.6/8/2*10/10 : 0 ;
for my $i (44..47) {
my $rlp = $data[$i];
$sum{$cell}{$sect}{$carr}{$dist} += $rlp if $rlp;
}
}
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: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/