Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have been using an auditing script which is a cgi for months now all working fine and dandy. One of the subroutines pulls back mcafee AV Info from the registry. Suddenly its stopped working and producing the error, although the only thing i have done is added a few subroutines further down the code !!! What can this be refering to ? Code Below:- edited by boo_radley : added readmore tag
sub mcafee { # carry out Reg Query and action as required use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1 ); $Registry->Delimiter("/"); # Set delimiter to "/". $remKey= $Registry->Connect( "$server", "LMachine", { Access=>KEY_READ +,Delimiter=>"/" } ); $regkey = $remKey->{"Software/network associates/tvd/netshield nt/curr +entversion/szenginever"}; # print "@$regkey[0]\n"; # Print it (note it is a reference to an a +rray -hence the @$)uncomment for bug fixing print "ANTI VIRUS INFORMATION: \n"; print "------------------------"; print "\nNetshield Anti Virus Engine Version $regkey\n"; # Pri +nt it (note it is a reference to an array -hence the @$) # Get the location where the upgrade will come from $Registry->Delimiter("/"); # Set delimiter to "/" +. $remKey= $Registry->Connect( "$server", "LMachine/", { Access=>KEY +_READ,Delimiter=>"/" } ); # Connect to remote registry $regkey= $remKey->{"Software/network associates/tvd/netshield nt/c +urrentversion/tasks/upgrade//szupdateunclocation"}; $upguser= $regkey->{"Software/network associates/tvd/netshield nt/ +currentversion/tasks/upgrade//szrunasuser"}; print "Engine Update Source Server $regkey. Using this account - +$upguser\n"; # get dat file version $Registry->Delimiter("/"); $remKey= $Registry->Connect( "$server", "LMachine/", { Access=>KEY +_READ,Delimiter=>"/" } ); # Connect to remote registry $regkey= $remKey->{"software/network associates/tvd/netshield nt/c +urrentversion//szvirdefver"}; print "\nVirus Definition file version $regkey\n"; # get dat file date $Registry->Delimiter("/"); $remKey= $Registry->Connect( "$server", "LMachine/", { Access=>KEY +_READ,Delimiter=>"/" } ); # Connect to remote registry $regkey= $remKey->{"software/network associates/tvd/netshield nt/c +urrentversion//szvirdefdate"}; print "Virus Definition file date $regkey\n"; # Get the location where the update comes from .. $Registry->Delimiter("/"); $remKey= $Registry->Connect( "$server", "LMachine/", { Access=>KEY +_READ,Delimiter=>"/" } ); # Connect to remote registry $regval= $remKey->{"software/network associates/tvd/netshield nt/c +urrentversion/tasks/update//szupdateunclocation"}; $upduser= $remKey->{"software/network associates/tvd/netshield nt/ +currentversion/tasks/update//szrunasuser"}; print "Virus Update definition file source $regval . Using this a +ccount - $upduser\n"; # Get Alerter info. $Registry->Delimiter("/"); $remKey= $Registry->Connect( "$server", "LMachine/", { Access=>KEY +_READ,Delimiter=>"/" } ); # Connect to remote registry $regval= $remKey->{"software/network associates/tvd/shared compone +nts/alert manager/recipients//recipient0"}; print "\nVirus Alerts:\n"; print "-------------"; print "\nAnti Virus Alert recipient 0 set to: $regval: "; $regval= $remKey->{"software/network associates/tvd/shared compone +nts/alert manager/recipients//recipient1"}; print "\nAnti Virus Alert recipient 1 set to: $regval: "; $regval= $remKey->{"software/network associates/tvd/shared compone +nts/alert manager/recipients//recipient2"}; print "\nAnti Virus Alert recipient 2 set to: $regval: "; # Get Scheduler Info. print "\n\nScheduler Info\n"; print "--------------\n"; $Registry->Delimiter("/"); $remKey= $Registry->Connect( "$server", "LMachine/", { Access=>KEY +_READ,Delimiter=>"/" } ); # Connect to remote registry $regval= $remKey->{"software/network associates/tvd/Netshield NT/C +urrentVersion/Tasks/Update//bSchedEnabled"}; if ($regval=="0x00000001") { $schedenabled="Yes"; } else { $schedenabled="No"; } print "Update Scheduler enabled: $schedenabled\n"; # Get Upgrade Sched info $Registry->Delimiter("/"); $remKey= $Registry->Connect( "$server", "LMachine/", { Access=>KEY +_READ,Delimiter=>"/" } ); # Connect to remote registry $regval= $remKey->{"software/network associates/tvd/Netshield NT/C +urrentVersion/Tasks/Upgrade//bSchedEnabled"}; if ($regval=="0x00000001") { $schedenabled="Yes"; } else { $schedenabled="No"; } print "Upgrade Scheduler enabled: $schedenabled\n"; }

Replies are listed 'Best First'.
Re: Weird Error:Can't coerce array into hash
by rob_au (Abbot) on Jan 22, 2003 at 11:24 UTC
    The perldiag documentation describes this fatal error as follows:

    You used an array where a hash was expected, but the array has no info +rmation on how to map from keys to array indices. You can do that on +ly with arrays that have a hash reference at index 0.

    Google returns a number of pages that reference a range of scenarios which generate this error message, most often referring to errors in dereferencing.

    As such, more information is really needed to sort this error out, namely, the specific line where this error is occurring and the surrounding code which contributes to values used within the hash assignment on that line.

     

    perl -le 'print+unpack("N",pack("B32","00000000000000000000001000100101"))'

Re: Weird Error:Can't coerce array into hash
by grinder (Bishop) on Jan 22, 2003 at 11:26 UTC

    Can you cut the script down to isolate the problem? Wading through the thickets of print statements in your code make it hard to identify where you might be using hashes. You don't say which line the error appears on.

    I had a much simpler problem that produced the same error, and I posted a SoPW on the question a while back. You might want to take a look at Coercing an array into a hash and see if it rings a bell.

    And pretty please, settle on a better way to format your code, learn how to use heredocs, or a templating tool such as Template Toolkit. Your code will be much more readable, your life will improve and girls will stop and... well, maybe not...


    update: linked to TT homepage.


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
      sorted it, it was due to one of the new subroutines redeclaring the use win32::TieRegistry blah blah line :) Whats the template toolkit btw ??
Re: Weird Error:Can't coerce array into hash
by mowgli (Friar) on Jan 22, 2003 at 11:15 UTC

    Exactly where is the error you mention occuring - i.e., at which line etc.? It might be helpful if you posted the whole script, too, if that's possible.

    Also, have you modified anything else about the system that this is running on?

    --
    mowgli