469,579 Members | 1,098 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Storing an Array in a Hash

Hi,

I'm having a problem storing an array inside of a hash. I'm bringing
in a hash via a reference and I want to assign a value to it. This is what
I'm doing:
push (@{$$node->{ELEMENTS}}, "New value");

(I need to use "push" because this is going in a for-loop)

However, when I run the script, I get the following:

Can't use string ("0") as an ARRAY ref while "strict refs" in use at ......
How do I solve this?

THanks
Jul 19 '05 #1
1 11010
Here is how I put values into a hash of arrays without push() that worked
pretty good with a for loop

$ar = [];

%ref = ( 'ELEMENTS' , $ar );

for ( $x=0; $x < 100; $x++ ) {

$ref->{ELEMENTS}[$x] = "new Value";

}

You can get the reference like this:

$arrayref = $ref->{ ELEMENT }

push( @$arrayref, "new Element" ); # something like that if you need the
push()
"Hale" <ep**@yaho.com> wrote in message
news:uy*******************@twister.socal.rr.com...
Hi,

I'm having a problem storing an array inside of a hash. I'm bringing
in a hash via a reference and I want to assign a value to it. This is what I'm doing:
push (@{$$node->{ELEMENTS}}, "New value");

(I need to use "push" because this is going in a for-loop)

However, when I run the script, I get the following:

Can't use string ("0") as an ARRAY ref while "strict refs" in use at .......

How do I solve this?

THanks

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by R. Rajesh Jeba Anbiah | last post: by
5 posts views Thread by Stijn van Dongen | last post: by
9 posts views Thread by Crirus | last post: by
8 posts views Thread by rgparkins | last post: by
3 posts views Thread by Brian | last post: by
2 posts views Thread by computerboy | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.