Hi,

On 16 Jan, 2012, at 16:19 , Robert Klemme wrote:

> On Mon, Jan 16, 2012 at 3:17 PM, Emil Enem=E6rke =
<eme / medical-insight.com> wrote:
>> Hi,
>>=20
>> Im trying to make an array a global array, but I cannot make it work.
>=20
> "server" references a Hash.
>=20
>> Here is what I have:
>> ------------
>> hostname=3Dserver1
>> server =3D Hash.new { |hash, key| hash[key] =3D [] }
>> service_name=3D"service name"
>> service=3Dservice1
>>=20
>> if server.key?(hostname)
>=20
> Will likely return false because the Hash is empty initially.
That was the intention, if the hash is empty create it.
>=20
>>      server[hostname]=3DHash.new { |hash, key| hash[key] =3D [] }
>>      server[hostname]["service_name"]=3DArray.new
>>      server[hostname]["service_name"]=3D"service#{service_counter}"
>>      server[hostname]["service_name"]=3D[x,x,x]
>=20
> The three lines above all overwrite the same entry.  That's almost
> certainly not what you want.
>=20
>> end
>> -----------------
>>=20
>> I have tried with
>> $server[hostname]["service_name"]=3D[x,x,x]
>> $server[hostname]["service_name"]=3DArray.new
>>=20
>> but that does not work... Any help is appreciated.
>=20
> I am not 100% sure what you intend but I think you might just want
>=20
> server =3D Hash.new { |hash, key| hash[key] =3D {} }
> server[hostname]["service_name"] =3D ["service#{service_counter}", =
[x,x,x]]
>=20
That is a much more elegant solution than mine, thanks.

But this does not solve my problem, I have the hash created within a =
loop but are not able to access to array from outside that loop, due the =
hash not being global. So how can I make the=20
server[hostname]["service_name"] =3D ["service#{service_counter}", =
[x,x,x]]
a global variable?

Kind Regards
Emil=