Thread Dateipfade hierarchisch in Hash speichern. (5 answers)
Opened by DocJones at 2010-08-28 16:26

moritz
 2010-08-28 16:43
#140998 #140998
User since
2007-05-11
923 Artikel
HausmeisterIn
[Homepage]
user image
Wenns dynamisch sein soll, brauchst du eine Schleife:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use strict;
use warnings;
use Data::Dumper;

sub hashify {
    my $path = shift;
    my $h = {};
    my $current = $h;
    for (split '/', $path) {
        next unless length $_;
        $current->{$_} = {};
        $current = $current->{$_};
    }
    return $h;
}

print Dumper hashify('/foo/bar/baz/blubb');

View full thread Dateipfade hierarchisch in Hash speichern.