Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Not a HASH reference error

by mhearse (Chaplain)
on Feb 24, 2016 at 20:33 UTC ( [id://1156070]=note: print w/replies, xml ) Need Help??


in reply to Not a HASH reference error

Try dumping your hashref. It may not be what you think it is:
use Data::Dumper; print Dumper($hashref);

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

    Okay, where should I put that? Should that be at the top of the perl script or in lines 41 or 55? Thanks

      Actually I think I got it. Here is the output:

      /www/configs/DB2/HLBROKDB/scripts/ScriptConfig.Driver.sh /www/configs/ +DB2/HLBROKDB/config/ScriptConfig.HLBROKDB-PROD.xml prodwxbat204as1l Remove control-Ms from config script /www/configs/DB2/HLBROKDB/config/ +ScriptConfig.HLBROKDB-PROD.xml ... Uncataloging items in /www/configs/DB2/HLBROKDB/config/ScriptConfig.HL +BROKDB-PROD.xml main::awc_db2_mgmt_kick running uncatalog for dcs entries $VAR1 = { 'db' => { 'HLBROKDB' => { 'node' => 'HLBROKDB' } }, 'dcs' => [ {} ], 'node' => { 'HLBROKDB' => { 'server' => 'produdbhlbrokdb', 'port' => '54042' } }, 'changeLog' => [ 'Created by Praveenkumar Sampath on 2015-01- +06 05:05:59' ] }; Not a HASH reference at /www/was50/bin/awc_db2_mgmt.pl line 58. /www/was50/bin/awc_db2_mgmt.pl failed: Please investigate.
      47 # OUTPUT returns true/false that the specified db2 configuration f +ile 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 use Data::Dumper; 56 print Dumper($hashref); 57 my $type_hash = $hashref->{$type}; + #shortcut to smaller hash 58 foreach my $item (keys %{$type_hash}) { 59 print "$log_pre running $action for $type +$item\n"; 60 my $item_hash = $type_hash->{$item}; + #shortcut to smaller hash 61 #Add values for type and action into the h +ash 62 $item_hash->{'name'} = $item; 63 $item_hash->{'type'} = $type; 64 $item_hash->{'action'} = $action; 65 print Dumper($hashref); 66 #execute action for the individual configu +ration 67 unless (db2_mgmt_cat(\%{$item_hash})) { 68 #unless (db2_mgmt_cat(\%{$type_hash})) { 69 # Return false if the action could + not be completed successfully.
        main::awc_db2_mgmt_kick running uncatalog for dcs entries
        'dcs' => [ {} ],

        So your problem is that $hashref->{'dcs'} is a reference to an Array of Hashes (AoH)

        my $type_hash = $hashref->{$type}; # not a hash ref foreach my $item (keys %{$type_hash}) { # can't de-ref to hash
        poj
Re^2: Not a HASH reference error
by briandanderson1977 (Novice) on Feb 26, 2016 at 19:11 UTC

    Okay, so latest on this saga. I found out that on an older version of Linux running an older version of perl (v5.8.8), I get a warning but the command still executes: Pseudo-hashes are deprecated at /www/was50/bin/awc_db2_mgmt.pl line 56. Now, on a more recent version of Linux running a newer version of perl (v5.10.1), this just blows up. No warning, just errors out. UGGGH HELP!!!

      If you know the pseudo-hashes are empty of data then a simple check and skip might suffice

      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}; next unless ref($type_hash) eq 'HASH'; # <-- add

      If you are not sure then use

      foreach my $type (@type_order) { # Iterate over all items of that type my $type_hash = $hashref->{$type}; if ( (ref($type_hash) eq 'ARRAY') && (@$type_hash<2) ){ print "Skipping empty pseudo-hash for $type entries\n"; next; } else { print "$log_pre running $action for $type entries\n"; } . .
      poj

        Thank you, Poj. What is really strange is this works just fine on another RHEL v6 server. But not on this one. Same syntax, everything. I'll try your recommendations and see what happens. Thanks again.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1156070]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-03-29 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found