Thread Subroutine & Arrays: Funktion zur Arrayerzeugung (11 answers)
Opened by Kristop8 at 2005-10-17 15:57

esskar
 2005-10-17 16:27
#58939 #58939
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
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
use strict;
use warnings;

my $dir = "c:/test";
my @array;

GetDirs($dir, \@array);

sub GetDirs {
  my ($directory, $arrayref) = @_;

  $directory =~ s!\\!/!g;
  $directory =~ s!/$!!;
 
  if(opendir(my $dir, $directory)) {
     while(my %entry = readdir $dir) {
         next if $entry =~ m!^\.\.$?!;
         
         my $path = "$directory/$entry";
         push @{$arrayref}, $path;
         GetDirs($path, $arrayref) if-d $path;
     }
     closedir $dir;
}
} #End GetDirs

print join("\n", @array);


ungetestet!\n\n

<!--EDIT|esskar|1129552114-->

View full thread Subroutine & Arrays: Funktion zur Arrayerzeugung