[tpm] dereferencing anonymous hashes

Shaun Fryer sfryer at sourcery.ca
Tue Apr 10 13:29:25 PDT 2007


# ah yes .. and I forgot the actual question. lol

%x = ( this => that );

# the value of 'this' can be obtained by doing this

$y = $x{this};

# howver as a hash reference...

$x = { this => that };

$y = $x->{this}; # you must use a 'pointer' to dereference the value

--
    Shaun Fryer
    tf: 866-920-9209

On Tue, Apr 10, 2007 at 04:23:27PM -0400, Shaun Fryer wrote:
> On Tue, Apr 10, 2007 at 02:58:33PM -0400, Fulko Hew wrote:
> > It makes me wonder then... whats the subtle difference
> > between
> > $x = () and $x = {} when dealing with hashes and their references?
> 
> @x = (); # this is an array
> %x = (); # this is an array, in hash context
> $x = \@x; # this is a reference to an array
> $x = \%x; # this is a reference to a hash
> $x = []; # this is a reference to an array
> $x = {}; # this is a reference to a hash
> 
> So one might do this...
> 
> @x = qw( three element array );
> $x = \@x;
> 
> ...or...
> 
> $x = [ qw( three element array ) ]; # same thing


More information about the toronto-pm mailing list