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 "stuff\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;

