Why doesn't the file descriptor need a sigil in Perl?

In Perl, filehandle is a data type, and I would expect a variable of this type to have some kind of sigil prefix. However, the following code (2nd open) shows that this is not the case

open my $fileHandle, '>', "out.txt";
open FH, '>', "out2.txt";

I found that the second form of confusion / inconsistency. What is the reason for resolving the second form?

+4
source share
2 answers

, . , . glob glob, filehandle filehandle. ( ).

.

+6

, .

my $fh = STDOUT;    # XXX Short for: my $fh = "STDOUT";
my $fh = *STDOUT;   # ok

, glob (, open, print, readline aka <> ..), .

print STDOUT "foo\n";   # Short for: print *STDOUT "foo\n";

*.

sub foo { }
sub bar(*) { }

foo(STDOUT);   # XXX Fails when using "use strict;"
bar(STDOUT);   # ok

?

( ) open(my $fh, ...), 5.6. , (my) . , open(FH, ...) .

+4

Source: https://habr.com/ru/post/1662074/


All Articles