Thread FileHandle testen?: if(FH) (11 answers)
Opened by BratHering at 2005-06-09 00:44

BratHering
 2005-06-09 12:25
#55435 #55435
User since
2005-04-28
155 Artikel
BenutzerIn
[default_avatar]
[quote=betterworld,09.06.2005, 09:37][quote=sri,08.06.2005, 23:44]Sei etwas kreativ...
Code: (dl )
warn "Jo is noch offen" if fileno *HANDLE;
[/quote]
Es gibt auch ein Filehandle, welches 0 als fileno hat. (Das ist stdin.) Bei Deiner Abfrage wuerde das als geschlossen zählen.[/quote]
stimmt, daran habe ich nicht gedacht. :(
bleibt meine frage also immer noch offen.

in der ActivePerl bibliothek gibt es ein modul namens FileHandle und das hat eine OOP schnittstelle und kann sowas:

Quote
use FileHandle;

$fh = new FileHandle;
if ($fh->open("< file")) {
print <$fh>;
$fh->close;
}

$fh = new FileHandle "> FOO";
if (defined $fh) {
print $fh "bar\n";
$fh->close;
}

$fh = new FileHandle "file", "r";
if (defined $fh) {
print <$fh>;
undef $fh; # automatically closes the file
}

$fh = new FileHandle "file", O_WRONLY|O_APPEND;
if (defined $fh) {
print $fh "corge\n";
undef $fh; # automatically closes the file
}

$pos = $fh->getpos;
$fh->setpos($pos);

$fh->setvbuf($buffer_var, _IOLBF, 1024);

($readfh, $writefh) = FileHandle::pipe;

autoflush STDOUT 1;


...aber ohne OOP müsste man doch bestimmt auch prüfen können nach gültigkeit des FH ?\n\n

<!--EDIT|BratHering|1118305585-->

View full thread FileHandle testen?: if(FH)