gman1983 has asked for the wisdom of the Perl Monks concerning the following question:

Ok, cleaned it up alot, and the only error I'm getting now is: "Can't use string ("AdAh") as ARRAY ref while "strict refs" in use. Also, "AdAh" is coming from the first element in array @list3. So, I have it narrowed down to this statement the below statment. Also, can I splice out elements from the arrays on the fly (without having any problems). Thanks in advance. if (substr($my_pocket, 0, 2) eq substr($array_of_lists{$key}[$t], 0, 2)) Code:
my %array_of_lists = ('0' => [@list3], '1' => [@list4], '2' => [@list8 +99]); #my @array_of_lists = (@list3, @list4, @list899); ##Set my hand my $my_pocket = 'AcAd'; my ($key, $t); for $key ( 0 .. scalar(keys %array_of_lists)) { #The loop will iterate through each element (hand of current h +andlist) of the current row and remove any #hand that contains the cards assigned randomly above. for $t ( 0 .. scalar @{$array_of_lists{$key}} ) { #If the first card of the random hand above equal the firs +t card in the element I am currently on, then remove the element from + this handlist by #splicing it out. Or if the first card of the random hand +above equal the second card of the element (hand) I am currently spli +ce it out. if (substr($my_pocket, 0, 2) eq substr($array_of_lists{$ke +y}[$t], 0, 2)) { $array_of_lists{$key} = splice(@{$array_of_lists{$key} +}, $t, 1); } elsif (substr($my_pocket, 0, 2) eq substr($array_of_lists{ +$key}[$t], 2, 2)) { $array_of_lists{$key} = splice(@{$array_of_lists{$key} +}, $t, 1); } elsif (substr($my_pocket, 2, 2) eq substr($array_of_lists{ +$key}[$t], 0, 2)) { $array_of_lists{$key} = splice(@{$array_of_lists{$key} +}, $t, 1); } elsif (substr($my_pocket, 2, 2) eq substr($array_of_lists{ +$key}[$t], 2, 2)) { $array_of_lists{$key} = splice(@{$array_of_lists{$key} +}, $t, 1); } } }

Replies are listed 'Best First'.
Re: Hash of arrays
by GrandFather (Saint) on Dec 02, 2008 at 02:11 UTC
Re: Hash of arrays
by graff (Chancellor) on Dec 02, 2008 at 03:36 UTC
    As others have pointed out, your earlier thread on this topic contains a lot of useful information -- including an answer from me about why you are getting that specific error message regarding a string that can't be used as an arrayref.

    (The particular node I replied to had been posted by "Anonymous Monk", but I assume it must have been you -- maybe that explains why you didn't notice...)

Re: Hash of arrays
by monarch (Priest) on Dec 02, 2008 at 02:13 UTC
    This might sound silly, but try adding a few print statements around the line that is causing you trouble. e.g.
    print( STDERR "key is \"$key\"\n" ); print( STDERR "t is \"$t\"\n" );

    Run again and see if that brings up any obvious issues.

Re: Hash of arrays
by sasdrtx (Friar) on Dec 02, 2008 at 02:22 UTC

    It would be better if you had just appended this post to your original question.

    sas
      Results: Key is "0" t is "0" Key is "0" t is "1" Can't use string... They equal what they should equal.