For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2004 > How get a special value of an arrayfield stored in an hash?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How get a special value of an arrayfield stored in an hash?
Bastian Angerstein

2004-05-24, 9:31 am


I tought:
$index = 1

$var = ${$myhash{mykey}}[$index];

would do the trick.

But it donīt.


Any suggestions?

Ricardo Signes

2004-05-24, 9:31 am

* Bastian Angerstein <ang@nmc-m.dtag.de> [2004-05-24T08:07:37]
> $index = 1
> $var = ${$myhash{mykey}}[$index];


$var = $myhash{mykey}[$index]
$var = $myhash{mykey}->[$index]

Either will do.

--
rjbs

Jan Eden

2004-05-24, 9:31 am

Hi Bastian,

Bastian Angerstein wrote on 24.05.2004:

>I tought:
>$index =3D 1
>
>$var =3D ${$myhash{mykey}}[$index];
>
>would do the trick.
>
>But it don=B4t.
>
>
>Any suggestions?
>
>

Your syntax implies that there already is an anonymous array stored as valu=
e of $myhash{mykey}. You assign the second value within that array to $var.=
In this case, a more readable version could utilize arrow dereferencing:

$var =3D $myhash{mykey}->[$index];

But what you are trying to do (according to youzr subject line) is

$myhash{mykey}->[$index] =3D $var;

Or did I get you wrong?

- Jan
--=20
Hanlon's Razor: Never attribute to malice that which can be adequately expl=
ained by stupidity.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com