Thread Verzeichnisbaum: Flaches Array mehrdimensional printen (13 answers)
Opened by root at 2005-03-26 12:20

renee
 2005-03-26 14:23
#52970 #52970
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Vielleicht hilft Dir das als Ansatzpunkt:
Code: (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
38
#! /usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my %hash;
while(<DATA>){
next if($_ =~ /^\s*?$/);
$_ =~ s/^\s+//;
my $path = $_;
$path =~ s/^\///; #/
my ($key,$sub) = split(/\//,$path,2);
$hash{$key} = insert_rec($key,$sub,$hash{$key});
}
print Dumper(\%hash);

# insert_rec builds the hash recursivly.
# Parameters:
# key of anonymous hash that has to be expanded
# remaining path
# reference to hash
sub insert_rec{
my ($key2,$path,$hashref) = @_;
my ($key,$sub) = split(/\//,$path,2);
unless($sub){
$hashref->{$key} = {};
return($hashref);
}
$hashref->{$key} = insert_rec($key,$sub,$hashref->{$key}) if($sub);
return ($hashref);
}# end insert_rec

# ohne Leerzeichen:
_ _DATA_ _
verz1/datei4
test
verz1/verz2/verz3/file3
\n\n

<!--EDIT|renee|1111839859-->
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Verzeichnisbaum: Flaches Array mehrdimensional printen