Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Storing an Array in a Hash

Reply
Thread Tools

Storing an Array in a Hash

 
 
Hale
Guest
Posts: n/a
 
      12-28-2003
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


 
Reply With Quote
 
 
 
 
Kemper
Guest
Posts: n/a
 
      12-28-2003
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" <(E-Mail Removed)> wrote in message
news:uyFHb.30845$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
Benchmark segfault [Was: Array#inject to create a hash versus Hash[*array.collect{}.flatten] ] Michal Suchanek Ruby 6 06-13-2007 04:40 AM
Array#inject to create a hash versus Hash[*array.collect{}.flatten] -- Speed, segfault Anthony Martinez Ruby 4 06-11-2007 08:16 AM
storing a hash of a hash in a DBM database Colvin Perl Misc 3 12-30-2003 04:38 PM



Advertisments