closed filehandle

Alles, was Perl betrifft, kann hier besprochen werden.

closed filehandle

Postby max1 » 18. May 2008 15:50

Das Perl-Skript enthält den Befehl zum Lesen einer Datei:
open(READFILE, "<dateiname.txt");
while(my $text = <READFILE>){
print $text;

Der Befehl wurde korrekt ausgeführt und der Inhalt der Datei entsprechend im Browser widergegeben. Nachdem ich den Computer neu gestartet habe, wird der Befehl nicht mehr ausgeführt und der Inhalt der Datei im Browser entsprechend nicht mehr widergegeben, wobei ich keinerlei Änderung am Perl-Skript vorgenommen habe. Der error.log von Apache zeigt folgende Fehlermeldung an:
[Sun May 18 16:32:52 2008] -e: readline() on closed filehandle READFILE at C:/xampp/cgi-bin/ line 11.

Was läuft falsch? Wie kann der Fehler behoben werden?
Posts: 5
Joined: 18. May 2008 10:14

Postby Stevie Marvin » 15. October 2008 05:17

Closes the file or pipe associated with the file handle, returning TRUE only if stdio successfully flushes buffers and closes the system file descriptor. If the file handle came from a piped open close will additionally return FALSE if one of the other system calls involved fails or if the program exits with non-zero status. (If the problem was that the program exited non-zero $! will be set to 0.) You don't have to close FILEHANDLE if you are immediately going to do another open() on it, because open() will close it for you. (See open().) However, an explicit close on an input file resets the line counter ($.), while the implicit close done by open() does not. Also, closing a pipe will wait for the process executing on the pipe to complete, in case you want to look at the output of the pipe afterwards. Closing a pipe explicitly also puts the status value of the command into $?. Example:
open(OUTPUT, '|sort >foo'); # pipe to sort
... # print stuff to output
close OUTPUT; # wait for sort to finish
open(INPUT, 'foo'); # get sort's results
FILEHANDLE may be an expression whose value gives the real filehandle name.
Stevie Marvin
Posts: 4
Joined: 12. September 2008 14:01

Return to Perl

Who is online

Users browsing this forum: No registered users and 1 guest