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

Nested anonymous hashes

Status
Not open for further replies.

randy4126

Programmer
Jun 2, 2001
62
US
I recieve this error every time I run this piece of code. "Can't use string ("0") as a HASH ref while "strict refs" in use at ./CMTS_Collector.pl line 427." I am new to anonymous hashes so any help you can give would be appricated.




foreach $oid (keys %oids)
{
LogMessage("DEBUG", "DEBUG->Function = runSNMP :: OID = " . $oid);

my @id_numbers = keys %{$result_Hash->{$CMTS_Name}->{$oid}}; <<<<<<<Error is on this line

foreach my $id_number (my @id_numbers)
{
LogMessage(&quot;DEBUG&quot;, &quot;DEBUG->Function = runSNMP :: IDNumber = &quot; . $id_number);

open(FH, &quot;>>/home/rcooper/snmpcmts/snmpcmts_&quot; . $CMTS_Name . &quot;.out&quot;);
print FH $CMTS_Name . &quot;:&quot; . $oid . &quot;:&quot; . $id_number . &quot;:&quot; . $result_Hash->{$CMTS_Name}->{$oid}->{$id_number} . &quot;\n&quot;;
close(FH);
}
}


Thanks..

Randy
smiletiniest.gif
 
It could be that $result_Hash is zero and not a hash ref, or it could be that $result_Hash->{$CMTS_Name} is, since both of those are being treated as hash references. You could say 'no strict' and the error goes away, but the error is there for the reason of telling you the code and/or the data isn't formed like you intended (and is likely causing the code to work improperly). Check the two above values and make sure they're hash refs. Bets are the second one isn't.Could you show us how you're populating that data structure (assuming it's not overly long and complicated)?

________________________________________
Andrew - Perl Monkey
 
[tt]$result_Hash->{$CMTS_Name}->{$oid}[/tt] is also being used as a hash ref, and could be 0.
 
I found the problem. I was populating the hash wrong. Once I fixed that it worked great. Thanks for your help.

Randy
smiletiniest.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top