jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:
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).#!/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";
I thought I would use
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.foreach (@line) { ($one,$two,$three,$four,$five,$six,$seven) = $_; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Replacing a text field in a spreadsheet
by Nitrox (Chaplain) on Nov 21, 2002 at 16:06 UTC | |
by jonnyfolk (Vicar) on Nov 21, 2002 at 16:55 UTC |