Storing an Array in a Hash

H

Hale

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
 
K

Kemper

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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top