tobold.org

correct • elegant • free

△ comp.lang.perl △

◅ tricky i/o with files

deleting a record in a dbm database ▻

Filehandle as object instance variable?

In article <1995Jun23.163930.5307@netlabs.com>,
Larry Wall <lwall@netlabs.com> wrote:
>                                       The constructor for FileHandle
>objects in the POSIX module limps along by generating new symbols as it
>needs them.  It then returns a blessed reference to a typeglob, which
>should be usable as a filehandle anywhere.

Except in functions which accept either a filename or a filehandle,
such as the file test operators, or truncate...

    $ cat testcase
    use FileHandle; use POSIX;
    $f = new FileHandle '/tmp/foo', 'w'; $f->autoflush;
    print $f "file handles in Perl are perfectly horrid";
    truncate $f, 32 or warn "truncate failed: $!\n";

    $ perl5.001l testcase
    truncate failed: No such file or directory

According to trace, this actually calls

    truncate ("FileHandle=GLOB(0xbf368)", 32)

:-(

Tim.
--
Tim Goodwin        | "If you're used to paint-by-number, a blank canvas
Public IP Exchange | can be unsettling at first." -- Larry Wall

Original headers:

From: tim@pipex.net (Tim Goodwin)
Newsgroups: comp.lang.perl.misc
Subject: Re: Filehandle as object instance variable?
Date: 27 Jun 1995 15:48:11 +0100
Organization: PIPEX, 216 Science Park, Cambridge, England
Message-ID: <3sp5nb$fkb@pipe.pipex.net>
References: <3r08ua$bdl@adam.spu.edu> <1995Jun23.163930.5307@netlabs.com>
NNTP-Posting-Host: pipe.unipalm.co.uk

△ comp.lang.perl △

◅ tricky i/o with files

deleting a record in a dbm database ▻