#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @daten = (
['hosen','jeans','modern'],
['hosen','shorts'],
['roecke','mini']
);
my $hash = {};
foreach my $data (@daten) {
if(ref $data eq 'ARRAY') {
my $max = scalar(@{$data});
my $start = $hash;
for my $i (1 .. $max) {
my $key = $data->[$i-1];
my $val = $i == $max ? 1 : {};
$start = prepareOrSet($start, $key, $val);
}
}
}
sub prepareOrSet {
my ($href, $key, $val) = @_;
$href->{$key} = $val unless defined $href->{$key};
return $href->{$key};
}
print Dumper $hash;