Thread Dateipfade hierarchisch in Hash speichern.
(5 answers)
Opened by DocJones at 2010-08-28 16:26
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'); |