Thread Unbestimmt tiefen HashinHash erzeugen (14 answers)
Opened by scriptor at 2009-08-09 00:58

scriptor
 2009-08-09 11:00
#123988 #123988
User since
2008-05-07
69 Artikel
BenutzerIn
[Homepage] [default_avatar]
So geht´s:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
sub hash {
    my ($ref, $hash) = @_;
    for my $el (@$ref) {
        $hash = $hash->{$el} ||= {};
    }
}

my $h = {};
my @array = qw/ a b c d e /;
hash( \@array, $h);
print Dumper( $h );

Egebnis:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
$VAR1 = {
'a' => {
'b' => {
'c' => {
'd' => {
'e' => {}
}
}
}
}
};

View full thread Unbestimmt tiefen HashinHash erzeugen