Thread Problem mit Storable (7 answers)
Opened by Jan at 2015-11-10 15:17

Daxim
 2019-11-21 09:42
#190918 #190918
User since
2007-08-01
114 Artikel
BenutzerIn
[Homepage]
user image
Wenn du nicht weiter enttäuscht werden willst, nimm CPAN:Sereal.
Code (perl): (dl )
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
use Path::Tiny qw(path);
use Sereal::Encoder qw(encode_sereal SRL_SNAPPY);
use Sereal::Decoder qw(decode_sereal);
use Test::More;
use Test::Deep qw(cmp_deeply);

my @categories = 1..100;
my $categoriesFile = glob "~/categories.sereal";

{
    my $path = path($categoriesFile);
    $path->filehandle({exclusive => 1}, '>');
    $path->spew_raw(encode_sereal \@categories, {
        compress => SRL_SNAPPY, croak_on_bless => 1
    });
}

{
    my $path = path($categoriesFile);
    $path->filehandle({exclusive => 1}, '<');
    my @categories2 = decode_sereal($path->slurp_raw, {
        refuse_objects => 1, validate_utf8 => 1
    })->@*;
    cmp_deeply \@categories, \@categories2;
}

done_testing;

View full thread Problem mit Storable