Schnellschuß:
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
use strict;
use warnings;
use CGI qw( :standard );
use File::Spec::Functions;
use Cwd;
my $cgi = CGI->new();
my $index = $cgi->param('index');
my @files = find_files_by_index( $index );
print "index: $index\n@files", $/;
sub find_files_by_index {
my $idx = shift;
my $dir = cwd();
my @files = ();
opendir my $dh, $dir or die "$dir: $!\n";
while ( my $file = readdir $dh ) {
my $fullpath = catfile( $dir, $file );
if ( !-d $fullpath and $file =~ m/_${idx}.[^.]+\z/ ) {
push @files, $file;
}
}
closedir $dh;
return @files;
}
Getestet auf der Kommandozeile:
Quote> dir
bla_I.xls blubb_i.xls nix_is.txt skript.pl
> perl skript.pl index=I
index: I
bla_I.xls
> perl skript.pl index=is
index: is
nix_is.txt
>
Fuer einen Test als CGI-Skript eines Webservers fehlen ein paar Sachen.
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!