Thread [Getopt::Long] getOptions - Fehlerermittlung bei gleicher Option (14 answers)
Opened by bora99 at 2015-09-10 11:41

bora99
 2015-09-10 14:08
#182134 #182134
User since
2009-12-05
54 Artikel
BenutzerIn
[default_avatar]
Code: (dl )
[b]$#[/b]... liefert den letzten Index im Array.

dachte, daß dies Anzahl der Array Elemente liefert, habe es aus einem anderen Perl abgekupfert, wo $#ARGV vorgekommen ist ...

Quote
Aber wieso > 2?
Ich dachte, die Option darf nur einmal vorkommen!

@option>2 bedeutet: scalar @option > 2 und das bedeutet Anzahl der Werte größer 2.
Du sagtest doch -o -o ist nicht erlaubt!?


dem ist natürlich so, jetzt habe ich wie folgt getestet
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 -w

use strict;
use Getopt::Long;

my %Args = ();
my @option = "";
my $option = "";

my $help = 0;

print "ARGV: @ARGV\n";

my $InOpts = GetOptions( \%Args,
'o|option=s' => \@option,
'h|help' => \$help ) or die "usage option ...";

print "Usage ..." if( ! $InOpts);
print "help ..." if( $help );

my $array_anz = @option;

print "ArrayInfo: Optionen: @option ArrayAnz: $array_anz \$#: $#option\n";

print "too much -o @option !!\n" if (@option>1);


Test:
testoption.pl -o option
Output:
ArrayInfo: Optionen: option ArrayAnz:2 $#: 1
too much -o option !!

Test:
testoption.pl -o option -o option
ArrayInfo: Optionen: option option ArrayAnz: 3 $#: 2
too much -o option option !!

darum habe ich @option > 2 verwendet

View full thread [Getopt::Long] getOptions - Fehlerermittlung bei gleicher Option