Hi dear all, I have written a script which reads the data lines and when a blank line is found all the data up to the previous line is considered as a one set and new set is started after the next line. Then I subtracted from one element of the last line of that set the same element of the first line of data. When I run this program, the trajectory travel time calculated is correct only for the first 3 trajectories and there after it is wrong. I can't understand why it gives correct value for first three trajectories. Can someone please help me?? My data file looks like follows:
5/1/2004 07:06:43 10 139.6668 35.52782 21.2 32952056 5593 0.86 25603 3 The script is as follows: #!perl/bin/perl ; use strict; #use warnings; my $i; my $j; my $data; my @line; my @time_in_seconds; my $travel_time; my $trajectory_travel_time; my @vid; open (FILE, " data.csv" ) || die " can't open the file"; open (OUT1, "> travel_time.csv") || die " can't open the file"; open (OUT2, "> trajectory.csv") || die " can't open the file"; $i = 0; $j=1; while (<FILE>) { $i++; $data = $_; chomp; @line=split /,/; $vid[$i] = $line[2]; if (@line != ()) { $time_in_seconds[$i] = $line[-2]; if ( $i==1) { $travel_time= 0; } else { $travel_time = $time_in_seconds[$i] - $time_in_seconds[1]; } print OUT1 "$_,$travel_time \n"; } else { $trajectory_travel_time = $time_in_seconds[-1] - $time_in_seconds[1]; print OUT2 "$vid[$i-1],Trajectory$j, $trajectory_travel_time \n"; $j++; $i=0; print OUT1 "\n"; } } When I turn on the " use warnings " it gives the warning ' Use of uninitialized value in numeric ne(!=) at ..... line 37, <FILE> line.. Here line 37 is" if (@line != ()) {" Kind regards, Geetha