Re: dereferencing
- From: krahnj@xxxxxxxxx (John W . Krahn)
- Date: Mon, 29 Oct 2007 17:50:34 -0800
On Monday 29 October 2007 15:23, Aaron Priven wrote:
I can do this:
my $hashref = \%hash;
But as near as I can tell, there is no way to do the reverse
operation: making a "my %hash" that is an alias for a hash reference.
Correct. You can alias a package variable but not a lexical variable.
It's possible with a package variable:
#/usr/bin/perl
our %hash;
my $hashref = { a => 5 , b => 8 };
*hash = $hashref;
You are not assigning to %hash you are assigning to the typeglob *hash.
Because $hashref contains a reference to a hash only the *hash{ HASH }
entry in the symbol table is affected.
print $hash{a};
that prints "5". But there's no way to do this with a lexical (my)
variable.
is this right?
Correct. Lexical variables are not part of the symbol table.
John
--
use Perl;
program
fulfillment
.
- References:
- dereferencing
- From: Aaron Priven
- dereferencing
- Prev by Date: Re: dereferencing
- Next by Date: One sprintf() initializations problem
- Previous by thread: Re: dereferencing
- Next by thread: printf problem
- Index(es):
Relevant Pages
|