I am running Strawberry Perl 5.24 on Windows 10. I have a question about Win32::TieRegistry. I am trying to use it to get information about a machine's processors. Based on my understanding of the documentation, I should be able to get it with this:
But it seems that nothing gets put in $idval. An attempt to print its value results in:use Win32::TieRegistry(Delimiter=>'/'); my $idval = $Registry->{"HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/Syste +m/CentralProcessor/0//Identifier"};
It seems that hashes are not being tied to each level of the registry. Printing the keys and values of $Registry produces the following:Use of uninitialized value $idval in concatenation (.) or string at C: +\Users\ ... \TieRegistry.pl line 9.
As I would expect, hash references are associated with most keys. But printing the keys and values of $Registry->{"HKEY_LOCAL_MACHINE"} produces this:Key: CConfig/ Value: Win32::TieRegistry=HASH(0x2a184b4) Key: CUser/ Value: Win32::TieRegistry=HASH(0x2a1834c) Key: Classes/ Value: Win32::TieRegistry=HASH(0x2a189ac) Key: DynData/ Value: Key: LMachine/ Value: Win32::TieRegistry=HASH(0x2f8d7ec) Key: PerfData/ Value: Key: Users/ Value: Win32::TieRegistry=HASH(0x2f8d1ec)
The keys look right, but no hash references. Any ideas as to what's going on? Please help.Key: BCD00000000/ Value: Key: DRIVERS/ Value: Key: HARDWARE/ Value: Key: SAM/ Value: Key: SECURITY/ Value: Key: SOFTWARE/ Value: Key: SYSTEM/ Value:
Here is my program (with 'use warnings' commented out to reduce clutter in the output):
Here is the output I get:use strict; # use warnings; use Win32::TieRegistry(Delimiter=>'/'); my ($idval, $k1); $idval = $Registry->{"HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/C +entralProcessor/0//Identifier"}; print "IDVAL: $idval\n"; $k1 = $Registry; print "\nregistry top level - $k1\n"; PrintHash($k1); $k1 = $Registry->{"HKEY_LOCAL_MACHINE"}; print "\nHKEY_LOCAL_MACHINE - $k1\n"; PrintHash($k1); $k1 = $Registry->{"HKEY_LOCAL_MACHINE/HARDWARE"}; print "\n$k1\n"; PrintHash($k1); sub PrintHash { my ($hashref, $indent) = @_; my %hash = %{$hashref}; $indent += 2; my $maxsize = 0; foreach my $key (keys %hash) { $maxsize = length $key if (length $key > $maxsize); } foreach my $key (sort keys %hash) { printf "%*sKey: %-*s Value: %s\n", $indent, "", $maxsize, $key +, $hash{$key}; if (ref $hash{$key} eq 'ARRAY') { PrintArray($hash{$key}, $ind +ent); } if (ref $hash{$key} eq 'HASH') { PrintHash($hash{$key}, $inde +nt); } } } sub PrintArray { my ($array, $indent) = @_; my @arr = @{$array}; $indent += 2; my $cnt = 0; foreach my $elem (@arr) { printf("%*s%2d. %s\n", $indent, "", $cnt, $elem); if (ref $elem eq 'ARRAY') { PrintArray($elem, $indent); } if (ref $elem eq 'HASH') { PrintHash($elem, $indent); } ++$cnt; } }
IDVAL: registry top level - Win32::TieRegistry=HASH(0x2a993bc) Key: CConfig/ Value: Win32::TieRegistry=HASH(0x2a184b4) Key: CUser/ Value: Win32::TieRegistry=HASH(0x2a1834c) Key: Classes/ Value: Win32::TieRegistry=HASH(0x2a189ac) Key: DynData/ Value: Key: LMachine/ Value: Win32::TieRegistry=HASH(0x2f8d7ec) Key: PerfData/ Value: Key: Users/ Value: Win32::TieRegistry=HASH(0x2f8d1ec) HKEY_LOCAL_MACHINE - Win32::TieRegistry=HASH(0x2f8d1d4) Key: BCD00000000/ Value: Key: DRIVERS/ Value: Key: HARDWARE/ Value: Key: SAM/ Value: Key: SECURITY/ Value: Key: SOFTWARE/ Value: Key: SYSTEM/ Value: Can't use an undefined value as a HASH reference at C:\Users\James\Por +table\strawberry-perl-5.24.0.1-32bit-portable\Perl Source\TieRegistry +.pl line 28.
In reply to Need help with Win32::TieRegistry by CrashBlossom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |