Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI and EOF

Status
Not open for further replies.

samesale

Programmer
Sep 15, 2003
133
US
I am trying to print a statment when the program hits the end of file. Is there a way to test for the eof?

if (EOF){
if($yes eq 'yes'0 {
print "EOF";
}
}

Pleas help.
 
What kind of file are you using? Generally, most files have and "end-of-file" marker but it varies depending on the application that created it. Your best bet is to trust in your script. If you use a "for each" or "do while" statement and it is properly constructed, when it finishes, you've reached the end of the file.

There's always a better way. The fun is trying to find it!
 
I use flat file. It is read with this statement:

open(GUEST, "<car.out") or dienice("Couldn't open auto.out for reading: $! \n");
while (<GUEST>) {
chomp;
($name,$add,$city,$state,$zip,$make,$photo)=split/\|/;

 
When you exit the while loop, you've finished reading the file. Just add your code there as tviman suggests.

Code:
open(GUEST, "<car.out") or dienice("Couldn't open auto.out for reading: $! \n");
  while (<GUEST>) {
# do something here
}
#at end of file.  Print statement here
 
Thanks to all of your with your help. I really appreciate your time and suggestions. I implemented the suggestion you made. However, it gives me error.

The partial program as below gives me this error:

syntax error at carsearch2.cgi line 7, near ") {"
syntax error at carsearch2.cgi line 8, near "}"
Execution of carsearch2.cgi aborted due to compilation errors.



eval {
open(GUEST, "<car.out") or dienice("Couldn't open auto.out for reading: $! \n");
while (<GUEST>) {
chomp;
($name,$add,$city,$state,$zip,$make,$photo,$model,$color,$mile,$eyear,$price,$email,$tele,$time,$comment1,$month,$day,$year)=split/\|/;

}
if (EOF) {
if ($yes eq 'no') {
print "<h2>Your match was not found. You may want to get back to the previous website and list the whole file or change your specifications. <br>";
print "<a href=\"/search.html\">Go Back to the Search Page</a><br>";
print "<a href=\"/sort.html\">Go Back to the Home Page</a></h2>";
}
}
}
}
 
I'm not sure that you need the if(EOF) statement. When you exit the while statement, you are at the end of the file. This seems to be what's causing your syntax errors. Try removing this line and running it again.

- Rieekan
 
Check the placement and number of curly braces {}, too. If you haven't defined EOF, it's going to give you an error. And like Rieekan says, you don't need the if statement at all.

There's always a better way. The fun is trying to find it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top