#! /usr/bin/perl use strict; use warnings; use Data::Dumper; use CGI::Carp 'fatalsToBrowser'; print "Content-type: text/plain\n\n"; my %hash; my $zaehler = 0; while(){     my $path = $_;     chomp $path;     next if($path =~ /^\s*?$/);     $_ =~ s/^\s+//;     $path =~ s/^\///; #/     next if(length $path < 2);     my ($key,$sub) = split(/\//,$path,2);     print "key: $key | sub: ".$sub."\n";     unless($sub){         $hash{$key} = 0;         next;     }     $hash{$key} = insert_rec($key,$sub,$hash{$key}); } my $outputstruktur = Dumper(\%hash); # Das was für das JS ausgegeben werden soll # Für das JS die { durch [ ersetzen $outputstruktur =~ s/}/]/g; #$outputstruktur =~ s/=>/,/g; $outputstruktur =~ s/\$VAR1/var TREE_ITEMS/g; # Variablennamen für JS ändern $outputstruktur =~ s/('\w+') => {/[$1, $zaehler/g; # quick and dirty # Ausgabe print $outputstruktur; # 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);     }     #print $sub."\n";     $hashref->{$key} = insert_rec($key,$sub,$hashref->{$key}) if($sub);     return ($hashref); }# end insert_rec # ohne Leerzeichen: verz1/datei1 verz1/datei2 verz1/datei3 verz1/datei4 file1 verz1/verz2/verz3/file1231 verz1/verz2/verz3/file1232 verz1/verz2/file121 verz1/verz2/file122 verz1/verz2/file123