in reply to dereferencing file handles

The problem is that print is using what is known as the "indirect object syntax", which requires a complex lookahead on Perl's part. The result is that complex operations that return a scalar are not going to do what you expect.

See the section labelled WARNING in perlobj for details. As for solutions, you can use the one that you stumbled on of putting the filehandle into a scalar, the block syntax suggested by another person which looks like:

print {$self->{_handle}} "string here";
Or you can take a speed hit and use IO::Handle and then
$self->{_handle}->print("string here");
Note that the last causes a speed hit, and its internal implementation causes some issues that tye has a complex fix for.

Replies are listed 'Best First'.
Re: Re (tilly) 1: dereferencing file handles
by Ryszard (Priest) on Sep 04, 2001 at 03:06 UTC
    Thanks for this. I've changed the $fh thingy to what you've suggested. it makes more sense in the code to read...
    I guess the answer is "you have problems dereferencing".. looks like i may have to read more.

    this will end up a part of a web application, so i dont think the speed hit is really an option.. ;-)

    thanks again ++ for you.