Getting to variables contained in a typeglob referenced by a scalar.
From: ddtl (this.is_at_invalid)
Date: 06/30/04
- Next message: Brad Baxter: "Re: Indented text converted to arrays of arrays"
- Previous message: Gunnar Hjalmarsson: "Re: HTTP::Request, trailing slash"
- Next in thread: Jaap Karssenberg: "Re: Getting to variables contained in a typeglob referenced by a scalar."
- Reply: Jaap Karssenberg: "Re: Getting to variables contained in a typeglob referenced by a scalar."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 30 Jun 2004 19:31:10 +0200
Hello,
After 'open' is called in the following way:
open my $fh, $file;
'$fh' contains a reference to a filehandle, i.e., somewhere in the 'open'
function there is probably a following assignment:
$fh = \*SOME_TYPEGLOB;
(and somehow that typeglob is anonymous (?), so the filehandle is
also anonymous).
If I understand correctly, it actually means that '$fh' contains
a reference to a typeglob, because wherever there is a filehandle,
it can be substituted for a typeglob.
Than, if we want to get to the variables inside that typeglob, we
have to do it in the following way:
*$fh - access the fileglob
*$fh->{SCALAR} - access a reference to a scalar (typeglob is also a special
hash)
${*$fh->{SCALAR}} - access the scalar itself.
But "Programming Perl" (14.4.1) mentions another, easier way -
just use $$$fh (or @$$fh or %$$fh, etc.).
I don't understand, though, how it works - what do we access when
$$fh is used - there is no scalar reference inside '$fh'?
The book doesn't mention it as some new way of using typeglobs/references,
which probably means that it should be clear from the previous chapters
why and how it works, and it seems that I missed the point.
The question is, then: how and why $$$fh etc. work, and where is an
explanation for it in the book (or just in the documentation)
ddtl.
- Next message: Brad Baxter: "Re: Indented text converted to arrays of arrays"
- Previous message: Gunnar Hjalmarsson: "Re: HTTP::Request, trailing slash"
- Next in thread: Jaap Karssenberg: "Re: Getting to variables contained in a typeglob referenced by a scalar."
- Reply: Jaap Karssenberg: "Re: Getting to variables contained in a typeglob referenced by a scalar."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|