T
thomasjbs
Getting strange error message: "Can't coerce array into hash at test.pl
line 21 with the following code: (line 22 with added comment)
I'm very new at using hashes and Perl on registry. The strange part is
that it gets through processing about 50 items before the error occurs.
The goal is to simply read the registy and print out a list of
installed applications. Although there might be simple methods to do
this, the secondary goal is to learn to use hashes.
Apparently the data is stored as a hash inside a hash.
Anyone know what's going on?
(run on Windows XP system with Activestate perl).
use Win32::Registry;
my $Register =
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
my ($hkey, @key_list, $key, @klist);
$cnt = 0;
$HKEY_LOCAL_MACHINE->Open($Register,$hkey)|| die $!;
$hkey->GetKeys(\@key_list);
print "$Register keys\n";
foreach $key (@key_list)
{
$tmpkey = $Register . "\\" . $key . $DisplayName;
$HKEY_LOCAL_MACHINE->Open($tmpkey,$q) or next;
$q->GetValues(\%klist);
#print $klist{'Display Name'},"\n";
while (($k,$d)=each(%klist)) {
if (lc $k eq "display name") {
print $tmpkey,"\n";
print $d,"\n";;
### Error is next line ###
$d = %$d;
print $k," ",$d,"\n";
#@e = %$d;
}
}
$q->Close();
# $cnt++;
print "$key\n";
}
print $cnt;
$hkey->Close();
line 21 with the following code: (line 22 with added comment)
I'm very new at using hashes and Perl on registry. The strange part is
that it gets through processing about 50 items before the error occurs.
The goal is to simply read the registy and print out a list of
installed applications. Although there might be simple methods to do
this, the secondary goal is to learn to use hashes.
Apparently the data is stored as a hash inside a hash.
Anyone know what's going on?
(run on Windows XP system with Activestate perl).
use Win32::Registry;
my $Register =
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
my ($hkey, @key_list, $key, @klist);
$cnt = 0;
$HKEY_LOCAL_MACHINE->Open($Register,$hkey)|| die $!;
$hkey->GetKeys(\@key_list);
print "$Register keys\n";
foreach $key (@key_list)
{
$tmpkey = $Register . "\\" . $key . $DisplayName;
$HKEY_LOCAL_MACHINE->Open($tmpkey,$q) or next;
$q->GetValues(\%klist);
#print $klist{'Display Name'},"\n";
while (($k,$d)=each(%klist)) {
if (lc $k eq "display name") {
print $tmpkey,"\n";
print $d,"\n";;
### Error is next line ###
$d = %$d;
print $k," ",$d,"\n";
#@e = %$d;
}
}
$q->Close();
# $cnt++;
print "$key\n";
}
print $cnt;
$hkey->Close();