store Array in hash ?



Hello,

I have setup a hash like the following:

my $test;

$test->{$setup}->{'opt'} = "OK";

It works fine, now I want to save an array to the hash:

my @data;

push(@data,"test");

$test->{$setup}->{'data'} = @data;

Now how do I use it in a for loop later in the script, I tried:

for(my $c=0; $c < $test->{$setup}->{'data'}; $c++) {
print $test->{$setup}->{'data'}[$c];
}

But that just returns:
Can't use string ("2") as an ARRAY ref while "strict refs" in use at ../imap-watch.pl line 380.

Michael
.



Relevant Pages

  • Re: Fwd: Re: dbm again
    ... The hash has only one key, ... Can't use string ) as an ARRAY ref while strict refs in ... It seems like I am somehow dealing with a reference to an array!? ... as a string and tried to be derefenced. ...
    (perl.beginners)
  • Re: searching an array reference
    ... > I have a class that is a hash and one of the hash values is an array ref. ... > Anyone know of a way of doing it without dereferencing it. ...
    (perl.beginners)
  • searching an array reference
    ... I have a class that is a hash and one of the hash values is an array ref. ... Anyone know of a way of doing it without dereferencing it. ...
    (perl.beginners)
  • Re: store Array in hash ?
    ... If so I can't because the data array keeps over written and reused again and again. ... now I want to save an array to the hash: ... Can't use string as an ARRAY ref while "strict refs" in use at ./imap-watch.pl line 380. ...
    (perl.beginners)
  • Duck Typed Concepts for Ruby (was Re: A use case for an ordered hash)
    ... An Sequencable mixin can be defined that implements all sorts of operations such as append, concat, splice, sort, etc. ... extending an instance of Array with Sorted if the array is known to be sorted. ... Now returning to the thread at hand we can see that the difference between the associative array and hash hierarchies is that the hash hierarchy depends upon Hashable keys. ...
    (comp.lang.ruby)