| Fredrik Y Andersson 2007-07-23, 6:59 pm |
| Hi
I'm trying to use multiple options with GetOptions
$>perl myprogram.pl --byggvy=abc --byggvy=def
How do you write the code for the GetOptions?
Best Regards
Fredrik Andersson
My code:
#!/usr/local/bin/perl
use warnings;
use Getopt::Long;
my %Options = ();
#Is this the correct way?
GetOptions(\%Options,
"edition=s" => \$edition,
"leveransdata=s" => \$leveransdata,
"help" => \$help,
"byggvy=s" => \@byggvy);
#Or is this the correct way?
#GetOptions(\%Options, "help", "edition=s", "byggvy=s@",
"leveransdata=s");
if ($Options{byggvy}) {
print "BYGGVY: $Options{byggvy}\n";
# Code for byggvy here
# I would like to have below code here [ii] but can't get this code to
work either
#I run the program like this: $>perl myprogram.pl --byggvy=abc --
byggvy=def
# How do I get the GetOptions data to the foreach loop?
# There is a directory called abc and def
} elsif ($Options{edition}) {
print "EDITION: $Options{edition}\n";
# Code for edition here
} elsif ($Options{leveransdata}) {
print "LEVERANSDATA: $Options{leveransdata}\n";
# Code for leveransdata here
} elsif ($Options{help}) {
print "HELP: $Options{help}\n";
} else {
print "HELP2: Show help text again\n";
}
#[ii]
use File::Copy;
foreach (@byggvy) {
$apexvy=$_;
system ("cp ./$apexvy/*.lfm /net/users/esbfran/XLEV/."); #or die
"Can't copy file $apexvy_wrk/*.lfm: $!";
system ("cp ./$apexvy/*.lfl /net/users/esbfran/XLEV/."); #or die
"Can't copy file $apexvy_wrk/*.lfm: $!";
system ("tar -cvf /net/users/esbfran/XLEV/$apexvy.tar $apexvy_wrk >/
dev/null"); #or die "Can't tar: $!";
}
|