By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,564 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,564 IT Pros & Developers. It's quick & easy.

Storing an Array in a Hash

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.