dereferencing



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.

It's possible with a package variable:

#/usr/bin/perl
our %hash;
my $hashref = { a => 5 , b => 8 };
*hash = $hashref;
print $hash{a};

that prints "5". But there's no way to do this with a lexical (my) variable.

is this right?

--
Aaron Priven, aaron@priven,com, http://www.priven.com/aaron



Relevant Pages

  • Re: Objects/Structures in Perl
    ... hashrefs, and all three point to the same hash. ... It's probably easier to simply create each hashref the way you want it: ... which strictly speaking defines printTime as a function ... See perldoc perlreftut and perldoc perldsc for some more pointers. ...
    (comp.lang.perl.misc)
  • Re: Difference with hash ref
    ... $plan_status is *absolutely* a hashref, as I have created it as such by ... "not a HASH reference", but with the braces, the program continues ... The braces create an anonymous hash and return a reference to that hash. ... labels =>, ...
    (perl.beginners)
  • Re: POE-Component-IRC & whois
    ... Sent in response to a 'whois' query. ... ARG0 is a hashref, ... $_is a hash reference, ...
    (comp.lang.perl.misc)
  • Re: effienct way to select random value from the hash
    ... scalar keys %$hashref; # reset iterator ... Since none of these are using the hash for lookup, ... Your while loop doesn't end so it would probably be less efficient. ...
    (comp.lang.perl.misc)
  • Re: Creating an alias to an existing hash (from a hash reference)
    ... Since I am not a fan of global variables, ... all the functions still referred to %hash (which at this ... sub f { ...
    (comp.lang.perl.misc)