hello, i'm writing a perl script to take in user info and and write it to a file. my current code:
it works fine, except for sometimes it inserts a blank line before adding the bowler.
Code:
#!/usr/local/bin/perl
print "Content-Type: Text/html\n\n";
$str=$ENV{QUERY_STRING};
($first, $second, $third) = split(/&/, $str);
($dummy, $newid) = split(/=/, $first);
($dummy, $newfName) = split(/=/, $second);
($dummy, $newlName) = split(/=/, $third);
open (bowlers, "bowl.dat") or die ("file didn't open");
@bInfo = <bowlers>;
close (bowlers);
foreach(@bInfo)
{
chomp(@bInfo);
($id, $therest) = split(/#/, $_);
if($newid == $id)
{
print "<html>\n";
print "<head>\n";
print "<title>Lake Side Bowling League: Add Bowler.</title>\n";
print "<meta http-equiv='REFRESH' content='2;url=http://tacosalad.lssu.edu/~neitrem/csci333/bowling/addbowler.html'>\n";
print "</head>\n";
print"<body>\n";
print "I.D. already exists<br />\n";
print "</body></html>\n";
$test = 0;
last;
}
else
{
$test = 1;
}
}
if($test == 1)
{
open(bowlers, ">>bowl.dat") or die("file didn't open");
print bowlers "\n$newid#$newlName#$newfName#";
close (bowlers);
print "<html>\n";
print "<head>\n";
print "<title>Lake Side Bowling League: Add Bowler.</title>\n";
print "<meta http-equiv='REFRESH' content='2;url=http://tacosalad.lssu.edu/~neitrem/csci333/bowling/index.html'>\n";
print "</head>\n";
print"<body>\n";
print "Bowler Added Successfully<br />\n";
print "</body></html>\n";
}
it works fine, except for sometimes it inserts a blank line before adding the bowler.