Thread Frage zur Autovivification bei Referenzen (8 answers)
Opened by bianca at 2022-01-03 14:36

bianca
 2022-01-03 14:36
#194129 #194129
User since
2009-09-13
6975 Artikel
BenutzerIn

user image
Moin und ein gesundes Neues!

Folgendes Script funktioniert:
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
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use Fcntl qw(:DEFAULT :flock);
use Date::Calc;
use Data::Dumper;
local $Data::Dumper::Purity;
$Data::Dumper::Purity = 1;
local $Data::Dumper::Useqq;
$Data::Dumper::Useqq = 1;
local $Data::Dumper::Deparse = 1;
$Data::Dumper::Deparse = 1;
local $Data::Dumper::Sortkeys;
$Data::Dumper::Sortkeys = sub {
    my ($hash) = @_;
    return [(sort {lc $a cmp lc $b} keys %$hash)]; 
};
system 'cls';


my $test = {
    foo     => {
        bar     => {
            baz     => {
                alf     => {
                    datei   => [2,4,6],
                },
            },
        },
    },
};

my $ast = $test->{foo}{barion}{und};
if (defined $ast) { say "check"; }

say "Autovivification Gegenprobe:\n".Dumper($test);

Unerwünscht ist das stattfindende Autovivification {barion}.
Wenn ich aber aus defined ein exists mache kommt
Quote
exists argument is not a HASH or ARRAY element or a subroutine at test.pl line 35.

Wie ist denn hierfür die richtige Syntax um auf Existenz des Asts zu prüfen ohne Autovivification zu haben?
10 print "Hallo"
20 goto 10

View full thread Frage zur Autovivification bei Referenzen