in reply to Re: Syntax for partly associative arrays
in thread Syntax for partly associative arrays

Thanks to you all. I think I have less knowledge than you're asuming. Yes, I meant what shenme said; I don't know how to make square brackets display (now I do - put them inside code tags). I tried what fletcher suggested, and it worked, but I still don't know how to refer to the first variable inside the second loop. When I run
#!/usr/bin/perl $a[1]{"blue"}=1; $a[1]{"red"}=2; $a[2]{"blue"}=3; $a[2]{"red"}=4; foreach $hash (@a) { foreach $word (keys %$hash) { print $firstval." ".$word." ".$hash->{$word}."\n"; } } I'd like to see 1 blue 1 1 red 2 2 blue 3 2 red 4
but I don't know how to set $firstval to see that. I understand the idea of arrays and references (is a hash an array of references?), but I know only by rote when to use @, $, and % for arrays (and %$ is new to me). So does this mean that anytime a multidimensional array is partly associative, I have to use foreach for all loops on it? I thought there was a way to use for $i (1..n) for the numerical variables and foreach for the others, but I don't remember it. Phil Rennert

Replies are listed 'Best First'.
Re: Re: Re: Syntax for partly associative arrays
by Anonymous Monk on Sep 08, 2003 at 14:43 UTC
    Looking again, I think shenme answered my question, -if- I have a list of all the words the second variable can be, which I can make if I need to. But it seems awkward, especially since the word lists for $i=1, $i=2, etc. aren't identical. I can union the lists and put in a does-not-exist test; but it seems kludgey: is there a cleaner way?