Thread RDW #1 - Rätsel der Woche Nummer eins (112 answers)
Opened by Crian at 2004-07-08 21:52

kabel
 2004-07-12 00:24
#83991 #83991
User since
2003-08-04
704 Artikel
BenutzerIn
[default_avatar]
hier noch ne lösung von mir:
Code (perl): (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
#!/usr/bin/perl
#
# baumrekursion mit Tie::Dir
#
use File::Spec;
use Data::Dumper;
use Tie::Dir;

sub scandir {
    my ($dir, $base) = @_;
    defined $base or $base = "";
    my %this_dir = ();
    my $abs_dir = File::Spec->catfile ($base, $dir);
    tie my %dir, Tie::Dir, $abs_dir;
    foreach (grep {not m/^(\.|\.\.)$/} keys %dir) {
        my $dirptr = File::Spec->catfile ($abs_dir, $_);
        -d $dirptr and $this_dir{$_} = {scandir ($_, $abs_dir)} or
        -f $dirptr and $this_dir{$_} = "";
    }
    untie %dir;
    return %this_dir;
}

my %dir = scandir (File::Spec->rel2abs (File::Spec->curdir ()));
print Dumper \%dir;


der tie ist sowas von unnötig :)

und wenn wir grad dabei sind: ich hab dir auch ne mail geschickt mit einer rdw-aufgabe; und noch keine antwort ...
-- stefan
Antworten mit Zitat

View full thread RDW #1 - Rätsel der Woche Nummer eins