#!/usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use CGI ':standard';
use Date::Calc qw(:all);
my $data="path/data.txt";
my $checkthree = param('check');
my $d = param('days'); #2 digit
my $m = param('months'); #2 digit
my $y = param('years'); #4 digit
my $Dd = param('Dd');
my $days = Date_to_Days($y,$m,$d);
my $count = 0;
my @Calendar;
while ($count < $Dd){
push (@Calendar, $days);
$count += 1;
$days += 1;
}
print header(), start_html;
open IN, $data or die "Cannot open $data for reading:$!\n";
my @line;
while (my $line =<IN>)
{
my ($one,$two,$three,$four,$five,$six,$seven) = split "\t",$line;
if ($three eq $checkthree) {
push (@Calendar, $seven);
my $replacementline = "$one,$two,$three,$four,$five,$six,@Calendar"
+;
push (@line, $replacementline);
last;
}
}
close IN;
print "@line";
The aim is to add new dates to those already in the spreadsheet in field $seven. Using input via DATE::CALC I have (finally) succeeded in combining the two sets of dates and getting them out of the 'while' loop in the form of an array (@line).
I thought I would use
foreach (@line) {
($one,$two,$three,$four,$five,$six,$seven) = $_;
}
To put the @line into the correct fields then read file $data into a temporary file with the new line and then rename the temp file.
Unfortunately I can't work out how to replace the new line with the old, and I was wondering if someone could give me some advice on how to get the array @line into the correct place in the spreadsheet (or some other way of doing it if I am not on the right track).
Thanks very much.