简体   繁体   English

从nstore_fd恢复错误:无法通过包“ Hash :: Case :: Lower”找到对象方法“ FIRSTKEY”

[英]Error restoring from nstore_fd: Can't locate object method “FIRSTKEY” via package “Hash::Case::Lower”

I am doing some archeology of a program from 2005. It's been happily writing backups like this: 我正在对2005年以来的某个程序进行考古。一直很高兴编写这样的备份:

use Storable qw(nstore_fd);  
my %data = 
    (
     "Games" => \%Games,
     "Members" => \%Members,
     "Scenarios" => \%Scenarios,
     "Passwords" => \%Passwords,
     "TourneyNames" => \%TourneyNames
     );

    nstore_fd(\%data, *BACKUP) or die "Can't write backup: $!";

I need to recover some of this data. 我需要恢复一些数据。

I did this: 我这样做:

use Storable qw(fd_retrieve); 

$data = fd_retrieve(*STDIN);  # the backup file 

print keys %{$data}, "\n";

foreach $thing (keys(%{$data})) {
    print "$thing\n";
    print scalar keys %{$data->{$thing}}, "\n";
}

and got: 并得到:

$ perl ~/foo.pl < BobsterBackup2018-7-9-35131.bak
GamesMembersPasswordsScenariosTourneyNames
Games
15556
Members
Can't locate object method "FIRSTKEY" via package "Hash::Case::Lower" at /Users/mgregory/foo.pl line 9.
$ 

I see that the original source has: 我看到原始来源有:

tie %Members, 'Hash::Case::Lower';    # index by non-case-sensitive member-name.

... but I'm at a loss what to make of it! ...但是我不知所措!

When you restore objects that are tied to packages, you first need to load their classes. 还原tied到软件包的对象时,首先需要加载它们的类。 Storable as well as, for example, Sereal will not load them for you. Storable ,例如Sereal不会为您加载它们。 It recreates the objects as they are stored, and Perl expects the packages to exist. 它会在存储对象时重新创建它们,而Perl希望这些包存在。

All you need to do is load the module before deserializing your backup. 您需要做的就是在反序列化备份之前加载模块。

use Storable qw(fd_retrieve); 
use Hash::Case::Lower;

my $data = fd_retrieve(*STDIN);  # the backup file 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM