LanX has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to understand how lexical filehandles are dumped:
> perl use Data::Dumper qw/Dumper/; use Data::Dump; open my $fh,"<",'/tmp/tst'; dd $fh; dd $::{'$fh'}; print Dumper $fh; __END__ \*main::$fh undef $VAR1 = \*{'::$fh'};
apparently $fh holds the ref to a glob named "\$fh" , i.e. with sigle as part of the name!
But inspecting the STASH doesn't show this entry...
I know that the common way to copy a bare filehandle to a scalar is my $fh=\*FH but this is confusing me.
Is this an implementation workaround or what am I missing?
Just after posting I'm realizing that I may be inspecting the wrong ($ = scalar) slot of the $fh glob. I'll update further tests.
OK inspecting only the glob reveals it's existence in the stash:
dd *{'::$fh'}; # => *main::$fh
but I'm still a bit confused ...
So lexical file handles are implemented as hidden global stash entries, which are destroyed when the lexical var falls out of scope ?
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: dumping lexical filehandles (not in STASH)
by tye (Sage) on Sep 12, 2014 at 17:26 UTC | |
by LanX (Saint) on Dec 13, 2014 at 18:57 UTC | |
|
Re: dumping lexical filehandles (solved)
by LanX (Saint) on Sep 12, 2014 at 15:32 UTC |