Thread Storable Fehlerausgabe ändern (3 answers)
Opened by bianca at 2020-03-14 20:13

haj
 2020-03-14 20:45
#191540 #191540
User since
2015-01-07
527 Artikel
BenutzerIn

user image
Aus CPAN:Storable:
Quote
Storable uses the "exception" paradigm, in that it does not try to workaround failures: if something bad happens, an exception is generated from the caller's perspective (see Carp and croak()). Use eval {} to trap those exceptions.

Also entweder Perldoc:perlfunc eval nutzen und dessen Fallstricke vermeiden (was in Deinem einfachen Szenario geht), oder eins der robusten CPAN-Module dafür nehmen wie CPAN:Try::Tiny.

Hier mit eval:

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
local $Data::Dumper::Purity;
local $Data::Dumper::Useqq;
local $Data::Dumper::Deparse = 1;
local $Data::Dumper::Sortkeys = sub {
        my ($hash) = @_;
        return [(sort {lc $a cmp lc $b} keys %$hash)]; 
};
use 5.010;
system('cls');

require Storable;
my %hin = (testkey => 'testvalue fuer den Key mit dem Code');

#
##
### SCHREIBEN
$Storable::Deparse = 1;
my $test = {
        test1           => 2,
        test2           => 4,
        test3           => 5,
        test4           => 6,
        codetest        => sub {
                my ($input) = @_;
                return $input->{testkey};
        },
};
say Dumper($test);
say "Test des Codes: '".$test->{codetest}->(\%hin)."'";

eval { Storable::lock_store($test,'/xxxxxx/file.sto'); };

if ($@) {
    say "FEHLER beim speichern: '$@'"; exit;
}
else {
    say "wurde gespeichert";
}

View full thread Storable Fehlerausgabe ändern