Hallo nochmal,
zumindest habe ich eine andere Lösung mit
Storable gefunden... - thx to phaylon =)
Mit nfreeze() und thaw() klappt es sehr gut. Es waere auch nicht besonders
toll gewesen, wenn ich etwas anderes hätte benutzen müssen, da Storable
auch noch die schnellste Lösung ist:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use strict;
use warnings;
use Benchmark;
use Data::Dumper;
use YAML;
use JSON;
use XML::Dumper;
use Storable qw(nfreeze thaw);
use Safe;
my $struct = {
s1 => [qw(v1 v2 v3 v4 v5 v6 v7 v8 v9 v0)],
s2 => {
s3 => [qw(v11 v12 v13 v14 v15 v16 v17 v18 v19 v20)],
s4 => 'v21',
},
s5 => [ { s6 => 'v22', s7 => 'v23' }, { s8 => 'v24', s9 => 'v25' } ],
s0 => 'v26',
};
sub xml_dumper {
my $dmp = new XML::Dumper;
my $p2s = $dmp->pl2xml($struct);
my $s2p = $dmp->xml2pl($p2s);
}
sub json {
my $json = new JSON;
my $p2s = $json->objToJson($struct);
my $s2p = $json->jsonToObj($p2s);
}
sub storable {
my $safe = new Safe;
$safe->permit(qw(:default require));
{
no warnings 'once';
$Storable::Deparse = 1;
$Storable::Eval = sub { $safe->reval($_[0]) };
}
my $p2s = nfreeze $struct;
my $s2p = thaw $p2s;
}
sub data_dumper {
my $p2s = Dumper($struct);
my $safe = new Safe;
my $s2p = $safe->reval($p2s);
}
sub yaml {
my $p2s = Dump($struct);
my $s2p = Load($p2s);
}
Benchmark::cmpthese(-1,{
'xml-dumper' => \&xml_dumper,
'storable' => \&storable,
'data-dumper' => \&data_dumper,
'yaml' => \&yaml,
'json' => \&json,
});
Rate yaml xml-dumper data-dumper json storable
yaml 107/s -- -74% -87% -87% -98%
xml-dumper 406/s 281% -- -49% -52% -92%
data-dumper 792/s 643% 95% -- -6% -84%
json 844/s 691% 108% 6% -- -83%
storable 5020/s 4606% 1135% 533% 495% --
Aber ich bin immer noch offen für andere Module! :)
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.