Hello,
there are more than one ways to do it...
1. Call the programm with a parameterlist where the last is the filename you are looking for and remove this name before starting find with my $filename = pop(@ARGV); and then compare each found filename with $filename
2. Use named parameters, e.g. with the Getopt::* - modules (e.g Getopt::Long)
3. Use named parameters and care for them by yourself, e.g. scriptname.pl --dir="/dir1/sdir1" --dir="/dir2/sdir2" --file="thisfile
+.txt"
I don't know if there are modules that handle this case. If not, you could do it like the following:
my $params = &GetParameters();
my @dirs = @{ $params->{dir} };
my @file = @{ $params->{file} };
# and so on
sub GetParameters {
my @allowedParams = qw(file dir);
die &PrintUsage() unless @ARGV;
my $params = {}; # shell contain parameters
foreach (@ARGV){
my ($key, $val) = split(/\=/, $_, 2); # split up by the first =
# test if $key is a valid parameter
unless ($key =~ s/^\-\-//) { # must start with --
die "Error: invalid param $key\n";
}
unless ( grep {lc($key) eq lc($_)} @allowedParams){
die "Error: param $key not allowed\n";
}
# maybe do some checks if $val is existing
....
# add param to hashreference $params
push (@{ $params->{$key} }, $val);
} # for
return ($params);
} # GetParameters
But before you use this code (which I haven't tested), better look if there's a module on CPAN that solves this problem.
Btw: i think programming with use strict; and use warnings; might be a very good idea, because it is much easier to find "silly" and "not-so-silly" errors that way
Best regards,
perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print" |