[PLUG] Perl hash/array/reference question

Keith Lofstrom keithl at kl-ic.com
Thu Oct 21 21:43:08 UTC 2004


PLUG perl hackers:

I'm learning Perl.  And Randal has the book royalties to prove it.
I am not sure where to ask newbie questions about Perl without some 
disgruntled eurotrash telling me to read some irrelevant FAQ I have
already read.  So I ask locally, because we orytrash are a lot
friendlier ...


I am trying to make a reference to a array referenced in a hash.

This works:

$a_hash{ $key }[0] = $foo ;  # autovivify
$a_hash{ $key }[1] = $bar ;

@an_array = $a_hash{ $key } ;
$an_array_reference = \@an_array ;

Now I do things like:  $fum = $$an_array_reference[1] ;
But not like:          $$an_array_reference[1] = $fum ;
  ... not if I want the element of the original hash array changed.


However, what I really want to do is something like ( pardon my 
strong C accent ):

$an_array_reference = \@a_hash{ $key } ;


I want to be able to write back to an element of the hash of arrays,
and I want to avoid copying arrays around.  

Is this possible?  What is the correct syntax?  What is the correct
thought process that leads to that syntax?  Where can I read about it?

Is there "Less Than One Way To Do It?"  

Keith

-- 
Keith Lofstrom          keithl at keithl.com         Voice (503)-520-1993
KLIC --- Keith Lofstrom Integrated Circuits --- "Your Ideas in Silicon"
Design Contracting in Bipolar and CMOS - Analog, Digital, and Scan ICs



More information about the PLUG mailing list