1,6064.86,85391.25,593.75,13.25 2,6072.17,85392.95,593.79,13.29 3,6078.94,85393.05,593.76,13.26 4,6085.51,85392.22,593.77,13.27 #### my $csv = Text::CSV->new(); open(OLD, '+<', $file) or die Lava::Message("Can't open original file"); while () { next if ($. == 1); if ($csv->parse($_) { my @columns = $csv->fields(); # open new file for editing open (TEMP, '>', $temp) or die Lava::Message("Can't open temporary file"); # extract pattern id from file name my $pattern = substr $file, -12 , 8; #date formatting doesn't work properly so i'll get the date from user my $select_date = ' '; my $date_panel = new Lava::Panel; $date_panel->text(' '); $date_panel->text(" Script Version: $Version"); $date_panel->text(' '); $date_panel->text(" SITE: YANDI"); $date_panel->text(' '); $date_panel->item("Type the date in format DD-Mon-YY: ", \$select_date, 9); $date_panel->execute('Date Selection') or return 0; #now print first two lines into the TEMP file print TEMP "$pattern ,"; print TEMP "$select_date"; print TEMP ",,Dist=Metres\n"; print TEMP "0,0.000,0.000,0.000,0.000,0.000,0.000\n"; while( ) { print TEMP $_; last if $. % 1; } # print the parsed body of old file print TEMP "$columns[0], $columns[2], $columns[1], $columns[3], $columns[0]\n"; } } # insert new lines at the end print TEMP "\n0, 0.000, 0.000, 0.000,\n"; print TEMP "0, 0.000, 0.000, 0.000, END\n"; close TEMP; close OLD; copy $temp, $file; #now we delete the temporary file Lava::Show("Deleting temporary file"); unlink $temp or Lava::Message "Couldn't delete the temporary file!"; END;