Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Hash within a Struct and keys()

Status
Not open for further replies.

zyphon08

Programmer
Jan 1, 2004
8
US
I'm using Class::Struct, and I created a struct that has a hash inside it. Now I want to loop through all of the elements in the hash using a foreach loop. The code looks like this..

foreach ( keys $games{$curGame}->matrix )
{
# stuff happens here...
}

%games is a hash of structs, and matrix is a hash within the struct that I'm trying to loop through. You can see how I'm trying to loop through it, but keys() apparently won't take that as an argument. So I'm wondering, how do I loop through its elements? (Also, kind of a side question.. is there a different way to do structs in perl? I really don't like Class::Struct)
 
Code:
foreach ( keys [COLOR=red]%{[/color]$games{$curGame}->matrix[COLOR=red]}[/color] )
{
# stuff happens here...
}

That ought to do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top