Thanks all.
Great explanation.
Roee

-----Original Message-----
From: Jonathan E. Paton [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 13, 2002 5:41 AM
To: [EMAIL PROTECTED]
Subject: Re: accessing an array in a hash


> How do I access a field in an array that is a field of a hash?
> ex:
> %hash
> $hash[1] =@array1
> $hash[2] =@array2
> .....
> 
> now I want to change $array2[6] via the hash.

The syntax is wrong, you use {} for hashes... and you wouldn't
normally use numerical indices.  Also, you need to take references
to the arrays.  When setting up hashes, this form is preferred:

my %hash = {
    key1 => \@array1,
    key2 => \@array2
};

Noting that you cannot store arrays in hashes, only
references to arrays.  Now, to get the reference of the
array in key1 you use:

print $hash{key1}

and by adding [] you can dereference that into an array:

print $hash{key1}[0];

you'll find it makes perfect sense... later.  You see,
this is the same as:

print $hash{key1}->[0];

just in case you wanted to find out what was going on.
You can have arrays of hashes of hashes of arrays of
objects, or whatever other weird structure comes to mind.

I hope this helps, 

Jonathan Paton

=====
---------------BEGIN GEEKCODE BLOCK-----------v3.12
GCS/E d+ s+: a20 C++(+++)>$ UHL++>+++ P+++ L++>++++
E- W++(-) N+ o? K- w--- !O M-- !V PS-- PE++ Y++ PGP
t@ 5-- X-- R- tv- b  DI+ D- G++ e h! !r--->++ !y---
----------------END GEEKCODE BLOCK-----------------
JAPH: print`perldoc perlembed`=~/(Ju.*)/,"\n"

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to