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
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/