Greetings Monks,

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:

use Win32::TieRegistry(Delimiter=>'/'); my $idval = $Registry->{"HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/Syste +m/CentralProcessor/0//Identifier"};
But it seems that nothing gets put in $idval. An attempt to print its value results in:
Use of uninitialized value $idval in concatenation (.) or string at C: +\Users\ ... \TieRegistry.pl line 9.
It seems that hashes are not being tied to each level of the registry. Printing the keys and values of $Registry produces the following:
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)
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: BCD00000000/ Value: Key: DRIVERS/ Value: Key: HARDWARE/ Value: Key: SAM/ Value: Key: SECURITY/ Value: Key: SOFTWARE/ Value: Key: SYSTEM/ Value:
The keys look right, but no hash references. Any ideas as to what's going on? Please help.

Here is my program (with 'use warnings' commented out to reduce clutter in the output):

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; } }
Here is the output I get:
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.