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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble getting a hash out of an object.

Status
Not open for further replies.

weathejx

Programmer
Jul 17, 2002
6
US
I've created an object that contains a hash table. However, when I try to iterate through the hash table, I get syntax errors. Any help would be greatly appreciated.

-j

Code:

foreach $key (keys %step->{actions}) {
print "\t$key\n";
}

sub new_step {
my $object = {
name => shift,
ypos => shift,
actions => {}
};
bless $object;
return $object;
} # end new_step
 
This might work:

Code:
foreach $key (keys %{step->{actions}}) {
    print "\t$key\n";
}

sub new_step {
    my $object = {
        name => shift,
        ypos => shift,
        actions => {}
    };
    bless $object;
    return $object;
} # end new_step

- Ben
 
That kinda worked. It runs now, but its not printing out any of the keys. Blast.

Any other ideas?
 
As a point of clarification, if i take that same foreach loop and put it right after where i fill the hash, it prints out fine. but in another sub routine it doesn't print. so somehow from one sub routine to another the hash get's deleted. ive run over my code a bunch and can't find any problems.

im sure this is some stupid problem that i just havent thought of yet.

thanks again for the help.

-j
 
Issue resoved. Thanks again for your help. It was something stupid. I was accidently incrementing a variable in the wrong spot.

-j
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top