Re: store Array in hash ?



Hey,

I think I am supposed to use a reference here ? If so I can't because the data array keeps over written and reused again and again.

I guess I will come up with a different solution.

Michael


Michael Gale wrote:
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: sort 1-D array of doubles for Olaf Schmidt
    ... Now I wonder if I could use this code to sort a variant 2-D array where the sorting columns holds ... original data array and only manipulate the lookup array of longs, ... Dim IndexList() As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: sort 1-D array of doubles for Olaf Schmidt
    ... Thanks for the reply, but I have no problem with the idea of the lookup array or index array or whatever you call it, but I just wanted to alter Olaf's code so that it would handle a 1-D array of doubles rather than a 1-D array of strings. ... At first you populate the array with the original indices into the data, then in your sort you use the value in this index array to lookup into the original data array to get its corresponding value. ... Dim IndexList() As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Kicking bindings to refresh a NSTableView
    ... > I have a minimal app with an NSTableView whose NSTableColumns have ... > However, if I unarchive the data array from disk, the table isn't ... provided you trigger the binding mechanism by ...
    (comp.sys.mac.programmer.help)
  • store Array in hash ?
    ... I have setup a hash like the following: ... 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)