in reply to Why don't file handles have sigils?
Why not think of STDIN, STDOUT and STDERR as a kind of constants? And really they look like nothing different, do they? Perl constants are used to be implemented as named subroutines with a zero-argument prototype, returning a filehandle reference.
Unfortunately however, passing an actual user-defined constant filehandle to print() will work only when wrapped in curlies, likewise would any other expression returning a filehandle:
use strict; sub FH () { open my $fh, '>', '/tmp/testfile.txt'; $fh } eval q{ print FH "Hello world!\n"; } or warn "Doesn't work - $@"; print {FH} "This works";
The curlies are recommended best practice for every time you must use type-globs, cf. Conway(2006). Think of it as type-glob derefencing with the star sigil omitted again.
Nowadays you should make lexical filehandles, how this is done has been already outlined in the thread.
|
|---|