Chris Stinemetz wrote:
Hello List,

Hello,

I'm stumped on this one.

I'm getting this error:

Use of uninitialized value in length at ./DBSR.pl line 21,<>  line 6.
Use of uninitialized value in length at ./DBSR.pl line 21,<>  line 8.
Use of uninitialized value in length at ./DBSR.pl line 21,<>  line 10.
Use of uninitialized value in length at ./DBSR.pl line 21,<>  line 13.
Use of uninitialized value in length at ./DBSR.pl line 21,<>  line 16.
Use of uninitialized value in length at ./DBSR.pl line 21,<>  line 23.
Use of uninitialized value in length at ./DBSR.pl line 21,<>  line 25.

  I just want to skip to the next line of input data if any of the
array elements have no value (0 in length).

#!/usr/bin/perl
use warnings;
use strict;
use POSIX;
use Data::Dumper;

my $fileOut = "testOut.txt";

open my $fin, '<', $fileIn or die "ERROR opening $fileIn: $!";
open my $out, '>', $fileOut or die "ERROR opening $fileOut: $!";

my @fields;

while(<>  ) {
   next unless /;/;
   chomp;
   my @data = split /;/;

If your data has empty fields at the end of the record then using split like that will not process those fields correctly. What you need is:

    my @data = split /;/, $_, -1;


   my($Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd) = @data[9,10,27,36,37,40];
     next if(length($Icell) == 0);
     next if(length($Isect) == 0);
     next if(length($cfc) == 0);
     next if(length($cfcq) == 0);
     next if(length($rtd) == 0);
     $rtd = sprintf "%.2f", $rtd/8/6.6/2;
     push(@fields, $Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd);
}
print Dumper \@fields;



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to