It looks like one of the elements of the array is undefined.
I'm also a little confused about what you're trying to print. For example:
The foreach is iterating over the elements of the array, and $hit is the value of each element, not the index. This is important later.SET: foreach $hit (@{$matches{$fastaseq}{$sitekey}}) {
This line prints the value of $hit. The following line, however,print "\$hit is: ",$hit,"\n";
uses that value as an index. I don't know how you populated the array, but unless the values of $hit really are index values, you're accessing possibly undefined array elements. In your example above, $hit = 6906413. Do you really have that many elements in the array?print "\$hit is: ",$matches{$fastaseq}{$sitekey}[$hit],"\n";
I suspect you may be having trouble with dereferencing, but I don't know enough about the data struct you have and what you're trying to get out to give you an example. Can you post a partial dump of %matches and an example of what you want to print?
Update: If you want to iterate over the array using indices instead of the values, you can use something like
If you want to simply skip undefined elements in the array, you can useforeach my $index ( 0 .. $#array )
next if( not defined $hit );
In reply to Re: foreach in HoHoA problems
by bobf
in thread foreach in HoHoA problems
by mdunnbass
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |