in reply to Re^2: Not a HASH reference error
in thread Not a HASH reference error

The significance is that line 56 is the earliest point at which Perl discovers there's a problem with line 55.

Line 55 grabs the value of a hash key. In this case, that hash key does not contain a hash reference (maybe doesn't exist at all). But this is no problem for Perl. If the key doesn't exist, then the value is undef. If it exists but isn't a hash reference, it still causes no problem for line 55. In line 56 you then try to dereference that value as though it were a hash. If the value was undef, that clearly cannot be dereferenced. And if the value was defined, but wasn't a hash ref, you also cannot dereference it as a hash. So at this point Perl has no idea what to do, and complains.


Dave

Replies are listed 'Best First'.
Re^4: Not a HASH reference error
by briandanderson1977 (Novice) on Feb 24, 2016 at 20:35 UTC

    AHHH okay, thank you for the information, that was very valuable. Here is what I found for $hashref within the script. It only shows up on line 49 and line 55.

    47 # OUTPUT returns true/false that the specified db2 configuration fi +le could be processed appropriately for the given action. 48 my $log_pre = whatsub(); 49 my ($action,$hashref,@type_order) = @_ or (warn "$log_pre +Invalid arguments" and return 0); 50 51 # Iterate over the configuration types listed in @type_ord +er 52 foreach my $type (@type_order) { 53 print "$log_pre running $action for $type entries\ +n"; 54 # Iterate over all items of that type 55 my $type_hash = $hashref->{$type}; + #shortcut to smaller hash 56 foreach my $item (keys %{$type_hash}) { 57 print "$log_pre running $action for $type +$item\n"; 58 my $item_hash = $type_hash->{$item}; + #shortcut to smaller hash 59 #Add values for type and action into the h +ash 60 $item_hash->{'name'} = $item; 61 $item_hash->{'type'} = $type; 62 $item_hash->{'action'} = $action; 63 #print Dumper($item_hash);

      After line 53, add this:

      die "$type doesn't exist in %{\$hashref}" or isnt a hash ref unless exists $hashref->{$type} && ref $hashref->{$type} eq 'HASH';

      The point is that the caller is passing $hashref, and @type_order. But one (or more) of the types in @type_order is either not a key in %{$hashref}, or the value of that key is itself not a hashref.


      Dave

        I tried adding that line that you asked me to add, but now it complains of having a configuration or compilation error. Here is what the perl script looks like now

        # Iterate over the configuration types listed in @type_order foreach my $type (@type_order) { print "$log_pre running $action for $type entries\n"; # Iterate over all items of that type my $type_hash = $hashref->{$type}; + #shortcut to smaller hash foreach my $item (keys %{$type_hash}) { print "$log_pre running $action for $type $ite +m\n"; die "$type doesn't exist in %{\$hashref}" or isnt a hash ref unless ex +ists $hashref->{$type} && ref $hashref->{$type} eq 'HASH'; my $item_hash = $type_hash->{$item}; + #shortcut to smaller hash #Add values for type and action into the hash $item_hash->{'name'} = $item; $item_hash->{'type'} = $type; $item_hash->{'action'} = $action; #print Dumper($item_hash); #execute action for the individual configurati +on unless (db2_mgmt_cat(\%{$item_hash})) {
        Please let me know what you think. I'm still getting the pseudo-hash error, I'm wondering if that has something to do with it. THANK YOU!!!