Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

printing

I'm trying to print a HoH with the following code.. but im getting the following error:

Can't use string ("nup") as a HASH ref while  "strict refs" in use for line 591 Can somebody tell me what this error is referring to and how I can fix it? thanks!
$hashfordefaults = { '42'=>{'BOOK'=>'HOT, FLAT AND CROWDED', 'AUTHOR'=>'FRIENDMAN', 'MODE'=>'2'}}
 
run($hashofhashes);
 
sub run{
   
   my $final = shift;
   print Dumper \%$final;
      for my $k1 ( keys %$final ) {
          print "$k1\n";
  
          for my $k2 ( keys %{$final->{ $k1 }} ) {
              print "\t$k2\n";
  
              for my $k3 ( keys %{$final->{ $k1 }->{ $k2 }} ) {
                  print "\t\t$k3 => $final->{ $k1 }->{ $k2 }->{ $k3 }\n";
              }
          }
    }
 
 }

Open in new window

0
cucugirl
Asked:
cucugirl
1 Solution
 
cucugirlAuthor Commented:
trying to print a reference to a hash of hashes of hashes I mean to say and this is it, forgot to write the last element
$hashfordefaults = { '42'=>{'BOOK'=>'HOT, FLAT AND CROWDED', 'AUTHOR'=>'FRIENDMAN', 'MODE'=>'2','UPDATE'=>'up'}}
0
 
Adam314Commented:
Your code assumes a HoHoH, but you have only a HoH.  Instead of your third for loop, you should just print the value.
sub run{
	my $final = shift;
	print Dumper \%$final;
	for my $k1 ( keys %$final ) {
		print "$k1\n";
		for my $k2 ( keys %{$final->{ $k1 }} ) {
			print "\t$k2";
			print " = $final->{$k1}->{$k2}\n"; #These 2 prints could be in 1
		}
	}
}

Open in new window

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now