G
Guy
Hi all, 
I wrote a Perl script to append Questions and Answers to a text data file.
The file would look like this and would grow when Q&As are added.
1 Q This is a question
1 A This is an answer
2 Q This is another question
2 A This is another answer
All I do is open the file for append, print 2 lines (Q line and A line) and
then close the file. What's happening however is that my data is appended
twice, like this: This is an actual cut & Paste of the entire file.
1 Q Here is my question
1 A Hee is my answer
2 Q Here is my question
2 A Hee is my answer
3 Q here is another question
3 A this is another answer
4 Q here is another question
4 A this is another answer
5 Q qqqqq
5 A zaaaaaa
6 Q qqqqq
6 A zaaaaaa
7 Q sdfkhj asdlfh fih asdfh ;alsdfh
7 A asdkfj; alsdfh ausf iaufh jkahf kawhef awef
8 Q sdfkhj asdlfh fih asdfh ;alsdfh
8 A asdkfj; alsdfh ausf iaufh jkahf kawhef awef
What's worst is that you notice on the above file that the count does
increment as if my routine is called twice. So what I've done was added a
few check-point print commands inside the routine and these only print once,
as if my routine is only called once.
Any ideas,
Guy
FYI
They tell me the server is a SUN Sparc V100 with dual 100mb ports.
The Web is provided by an iPlanet webserver.
It is Perl 5.008
Curious
Here is the code for the updating routine...
sub f25
{
my $chk=0;
my $number=0;
my $qaline;
my @qafield;
&prt_head; # Prints HTML code back to browser
$chk=get_qa(); # see below
if($chk==0)
{
foreach $qaline (@qafile)
{
@qafield=();
push(@qafield,split(/\t/,$qaline));
$number=$qafield[0];
}
print"Number = $number <BR> \n"; # checkpoint print command
$number++;
print"Number=$number<BR><BR><BR>\n"; # checkpoint print command
$chk=3840;
if(-d "$fd")
{
$chk=256;
if(open(FILE,">>$qafil"))
{
print"Added<BR>\n";
print FILE "$number\tQ\t$fq\t\n$number\tA\t$fa\t\n";
close(FILE);
print"Done<BR>\n";
$chk=0;
}
}
}
if($chk != 0){erreur($chk);}
print"</FORM></BODY></HTML>\n";
}
sub get_qa
{
my $chk=3840;
if(-d "$fd")
{
$chk=256;
if(open(FILE,"$qafil"))
{
@qafile=<FILE>;
close(FILE);
$chk=0;
}
}
return $chk;
}
I wrote a Perl script to append Questions and Answers to a text data file.
The file would look like this and would grow when Q&As are added.
1 Q This is a question
1 A This is an answer
2 Q This is another question
2 A This is another answer
All I do is open the file for append, print 2 lines (Q line and A line) and
then close the file. What's happening however is that my data is appended
twice, like this: This is an actual cut & Paste of the entire file.
1 Q Here is my question
1 A Hee is my answer
2 Q Here is my question
2 A Hee is my answer
3 Q here is another question
3 A this is another answer
4 Q here is another question
4 A this is another answer
5 Q qqqqq
5 A zaaaaaa
6 Q qqqqq
6 A zaaaaaa
7 Q sdfkhj asdlfh fih asdfh ;alsdfh
7 A asdkfj; alsdfh ausf iaufh jkahf kawhef awef
8 Q sdfkhj asdlfh fih asdfh ;alsdfh
8 A asdkfj; alsdfh ausf iaufh jkahf kawhef awef
What's worst is that you notice on the above file that the count does
increment as if my routine is called twice. So what I've done was added a
few check-point print commands inside the routine and these only print once,
as if my routine is only called once.
Any ideas,
Guy
FYI
They tell me the server is a SUN Sparc V100 with dual 100mb ports.
The Web is provided by an iPlanet webserver.
It is Perl 5.008
Curious
Here is the code for the updating routine...
sub f25
{
my $chk=0;
my $number=0;
my $qaline;
my @qafield;
&prt_head; # Prints HTML code back to browser
$chk=get_qa(); # see below
if($chk==0)
{
foreach $qaline (@qafile)
{
@qafield=();
push(@qafield,split(/\t/,$qaline));
$number=$qafield[0];
}
print"Number = $number <BR> \n"; # checkpoint print command
$number++;
print"Number=$number<BR><BR><BR>\n"; # checkpoint print command
$chk=3840;
if(-d "$fd")
{
$chk=256;
if(open(FILE,">>$qafil"))
{
print"Added<BR>\n";
print FILE "$number\tQ\t$fq\t\n$number\tA\t$fa\t\n";
close(FILE);
print"Done<BR>\n";
$chk=0;
}
}
}
if($chk != 0){erreur($chk);}
print"</FORM></BODY></HTML>\n";
}
sub get_qa
{
my $chk=3840;
if(-d "$fd")
{
$chk=256;
if(open(FILE,"$qafil"))
{
@qafile=<FILE>;
close(FILE);
$chk=0;
}
}
return $chk;
}