Win32 Registry.pm incosistent for nonexistent toplevel keys 
Author Message
 Win32 Registry.pm incosistent for nonexistent toplevel keys

Registry.pm exports toplevel keynames which may not exist on all systems.
The returned object from Open is sometimes undefined and sometimes
defined, based on the sate of the variable (that is to hold the object)
prior to the call.

this shows the code that demonstrates this and the results:
"
use diagnostics;
use Win32::Registry;

{
my $NewObj;
$HKEY_DYN_DATA->Open('',$NewObj);
print "Case 1: $NewObj\n";

$NewObj = 0;
$HKEY_DYN_DATA->Open('',$NewObj);
print "Case 2: $NewObj\n";

Quote:
}

{
my $NewObj;
$HKEY_LOCAL_MACHINE->Open('',$NewObj);
print "Case 3: $NewObj\n";

$NewObj = 0;
$HKEY_LOCAL_MACHINE->Open('',$NewObj);
print "Case 4: $NewObj\n";

Quote:
}

print "Perl Version is ", $];
__END__
C:\Data\perl_scripts>perl -w junk3
Use of uninitialized value at junk3 line 7 (#1)

    (W) An undefined value was used as if it were already defined.  It was
    interpreted as a "" or a 0, but maybe it was a mistake.  To suppress
this
    warning assign an initial value to your variables.

Case 1:
Case 2: Win32::Registry=HASH(0x110668c)
Case 3: Win32::Registry=HASH(0x1106af8)
Case 4: Win32::Registry=HASH(0x1101cf0)
Perl Version is 5.00502
C:\Data\perl_scripts>
"

This shows what I do about it:

for ( sort (keys %main::)) {
   if ( /^HKEY_[A-Z_]*/ ) {

    }

Quote:
}

# find the HKEY_ vars which Registry.pm puts into
# the main:: namespace


    print "$_\n";
    my $Dir = '';

    my $NewObj = undef;

    # check that the top level key is valid.  To be valid, the operation
    # must return a defined $NewObj and must have SubKeys or Values.
    # The check for subkeys and values is needed because even a
non-existent
    # key sometimes will return a $NewObj.
    {
    no strict 'refs';
    ${$_}->Open($Dir, $NewObj);
    # this is $HKEY_WHATEVER->Open($Dir, $NewObj);
    }
    # THE FOLLOWING 4 LINES OF CODE CHECK IF THE KEY RETURNED
    # A USEABLE NEWOBJ, AND IF ANY SUBKEYS AR VALUES EXIST.
    next if ( !defined $NewObj );

    $NewObj->GetValues(\%data);

    $hlist->add($_, -text=>$_);
    $hlist->indicator('create', $_, -text=>'+');

Quote:
}

"


Thu, 12 Apr 2001 02:00:00 GMT  
 Win32 Registry.pm incosistent for nonexistent toplevel keys
) Registry.pm exports toplevel keynames which may not exist on all systems.

And it exports them to main::, not whatever package the
"use Win32::Registry" was in.  And it was a bad design choice
to export objects with the same names as constants.  And...

I suggest you get libwin32 and switch to Win32::TieRegistry
and/or Win32API::Registry.  They even, *gasp*, come with
documentation.

If you build libwin32-0.13 with Perl5 that is not configured
to use PERL_OBJECT, then comment out the CAPI line in
APIRegistry/Makefile.PL to work around a bug in certain
versions of Perl5.
--
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)



Fri, 13 Apr 2001 03:00:00 GMT  
 Win32 Registry.pm incosistent for nonexistent toplevel keys
In a different forum someone suggested that I ... check the return code.
Doh!.

- Bob N.


: Registry.pm exports toplevel keynames which may not exist on all systems.
: The returned object from Open is sometimes undefined and sometimes
: defined, based on the sate of the variable (that is to hold the object)
: prior to the call.



Sun, 15 Apr 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Win32 Registry.pm incosistent for nonexistent toplevel keys

2. delete a non empty registry key with tie Registry

3. win32 registry keys for Perl

4. Associative array access with nonexistent key.

5. registry: can create key value but not key.

6. Win32::Registry.pm and packages

7. Problem writing .pm file with Win32::Registry included

8. Using Win32::Registry.pm

9. Using Win32::Registry.pm

10. Problem writing .pm file with Win32::Registry included

11. Win32::Registry remote registry access

12. Adding a value to a Registry key???

 

 
Powered by phpBB® Forum Software