为什么 Win32::TieRegistry 无法列出子项?
使用 Cygwin Perl v5.8.8 和 Win32::TieRegistry 0.26。
我们可以为 HKEY_CURRENT_USER 获取绑定哈希对象:
$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER"};
print Dumper $Key;'
$VAR1 = bless( {}, 'Win32::TieRegistry' );
这适用于子键:
$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper $Key;'
$VAR1 = bless( {}, 'Win32::TieRegistry' );
我们可以打印该键的信息:
$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper $Key->Information;'
$VAR1 = 'CntSubKeys';
$VAR2 = 48;
$VAR3 = 'MaxSubClassLen';
$VAR4 = 21;
...
但是文档暗示我们可以简单地通过将其视为哈希来列出子键:
$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper keys %$Key; '
但是数组是空的。 它坏了还是我做错了什么? 还有其他方法列出子键吗?
这也不起作用:
$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper $Key->SubKeyNames;'
Can't use an undefined value as an ARRAY reference at
/usr/lib/perl5/vendor_perl/5.8/cygwin/Win32/TieRegistry.pm line 720.
Using Cygwin Perl v5.8.8 and Win32::TieRegistry 0.26.
We can get a tied hash object thing for HKEY_CURRENT_USER:
$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER"};
print Dumper $Key;'
$VAR1 = bless( {}, 'Win32::TieRegistry' );
And this works for sub keys:
$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper $Key;'
$VAR1 = bless( {}, 'Win32::TieRegistry' );
And we can print information for the key:
$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper $Key->Information;'
$VAR1 = 'CntSubKeys';
$VAR2 = 48;
$VAR3 = 'MaxSubClassLen';
$VAR4 = 21;
...
However the documentation implies we can list the sub keys simply by treating it as a hash:
$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper keys %$Key; '
But the array is empty. Is it broken or am I doing something wrong? Is there another way to list the sub keys?
This doesn't work either:
$ perl -e '
my %RegHash;
use Win32::TieRegistry( TiedHash => \%RegHash );
use Data::Dumper;
my $Key = $RegHash{"HKEY_CURRENT_USER\\Software"};
print Dumper $Key->SubKeyNames;'
Can't use an undefined value as an ARRAY reference at
/usr/lib/perl5/vendor_perl/5.8/cygwin/Win32/TieRegistry.pm line 720.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用您的代码:
我在我的机器上得到了这个结果(WinXP,ActiveState Perl v5.10.0,Win32-TieRegistry 0.25):
这就是我从您的第二个代码示例中得到的结果:
所以您的两个代码示例在 ActiveState Perl 上都工作正常至少是Windows XP。
编辑:这看起来像一个更普遍的问题/错误:
With your code:
I get this result on my machine (WinXP, ActiveState Perl v5.10.0, Win32-TieRegistry 0.25):
and this is what I get with your second code sample:
So both of your code samples work okay, on ActiveState Perl and Windows XP at least.
EDIT: This looks like a more general problem/bug: