Thread Kommandozeile mit einem Schalter und zwei Argument: ein Argument fällt immer unter den Tisch (19 answers)
Opened by Timo_81 at 2006-09-12 18:19

renee
 2006-09-13 10:50
#69768 #69768
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
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
#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;

use vars qw($opt_d $opt_a $opt_h);

#
GetOptions("-a" => \$opt_a,
"-d" => \$opt_d,
"-h" => \$opt_h,);

help() if ($opt_h);

if ($opt_a){
print "not implemented.";
}
elsif ($opt_d){
my $base = shift(@ARGV);
my $base2= shift(@ARGV);

print $base;
print $base2;
}


Lies Dir bitte mal diesen Wiki:Artikel durch.

Wenn Du mal nicht nur reine Flags haben willst, sondern auch Argumente für die Optionen haben willst, dann muss es mal so aussehen:

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
28
29
30
#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long;

use vars qw($opt_d $opt_a $opt_h $argument);

#
GetOptions("-a" => \$opt_a,
"-d" => \$opt_d,
"-s=s" => \$argument,
"-h" => \$opt_h,);

help() if ($opt_h);

if ($opt_a){
print "not implemented.";
}
elsif ($opt_d){
my $base = shift(@ARGV);
my $base2= shift(@ARGV);

print $base;
print $base2;
}

if(defined $argument){
print $argument;
}


meh unter CPAN:Getopt::Long.
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Kommandozeile mit einem Schalter und zwei Argument: ein Argument fällt immer unter den Tisch