Do you mean pass command-line arguments? If so, checkout the module Getopt::Long. Otherwise, are you looking for something like below?
#!/usr/bin/perl -w
use strict;
use IO::Dir;
my $oggdir = '/media/tmp/';
ParseDirectory($oggdir);
sub ParseDirectory
{
my $dir = shift;
my $d = IO::Dir->new($dir)
or die "Can not open directory $dir for read!";
while (defined(my $f = $d->read))
{
if ($f =~ /.*_+.*\.[Oo][Gg]{2}$/) {
# matching files
my $new_name = $f;
$new_name =~ s/_//; # remove _
# rename $f to $new_name, etc.
} else {
# non-matching files
# do whatever, set to default, etc.
}
}
}
And an example of using Getopt::Long to parse command-line arguments:
#!/usr/local/bin/perl -w
use strict;
use Getopt::Long;
# Parse command line arguments and assign corresponding variables
GetOptions
(
'i|init=s' => \( my $INIT = undef ), # Specify the root director
+y
'u|upload' => \( my $UPLOAD = undef ),
'v|verbose' => \( my $VERBOSE = 0 ),
);
unless ( defined $INIT )
{
print <<EOF
Kapiti Exception Report
Usage: $0 [options]
Options:
-i|--init [file] Specify the path to initialization file
-u|--upload Upload the result into database
-v|--verbose Let the report generator print more information
EOF
;
exit(1);
}
# continue on...
|