in reply to (Continuation ....)Dynamic option

Adding options to data values is non-standard, in the extreme. You also appear to have multi-character options with only a single hyphen, -input instead of --input for example, which breaks the standard. Therfore I don't think any of the normal modules can help.

The only way I can see of doing this is to parse the argument list yourself. For example:
use warnings; use strict; # findfiles -input [-nd -na ] data [-nc -nd] modem apps -des "finding +files" -r 1000 # "finding files" altered to finding_files for test purposes our @ARGV = qw(-input -nd -na data -nc -nd modem apps -des finding_fil +es -r 1000); use Data::Dumper; use GetOpt::Std; my %args = ('-input' => [{}], '-des' => [{}], '-r' => [{}]); my $active_arg = 0; for my $arg (@ARGV) { if (substr($arg,0,1) eq '-') { if (exists $args{$arg}) { $active_arg = $arg } elsif ($active_arg) { $args{$active_arg}[0]{$arg} = undef } else { die "Invalid argument(1): $arg" } } else { if ($active_arg) { push @{$args{$active_arg}},$arg } else { die "Invalid argument(2): $arg" } } } print Dumper(\%args),"\n";
Gives:
$VAR1 = { '-r' => [ {}, '1000' ], '-des' => [ {}, 'finding_files' ], '-input' => [ { '-nc' => undef, '-nd' => undef, '-na' => undef }, 'data', 'modem', 'apps' ] };
You can then check to see if options have been set by using exists on the relevant hash.
Update: The problem with this though is that I am not setting the "sub-options" for the data items, for example -nd is duplicated. There is an inconsistency in your model so far as I can see. How do we know if 'data' should have options or not? Still, you might be able to develop my suggestion further, sicne you know what is valid and what is not.

Replies are listed 'Best First'.
Re^2: (Continuation ....)Dynamic option
by Anonymous Monk on Mar 16, 2011 at 12:31 UTC
    You also appear to have multi-character options with only a single hyphen, -input instead of --input for example, which breaks the standard.

    Getopt::Long supports single hyphen just fine for long options ...

    # x.pl # perl 5.8.8, Getopt::Long 2.35 use Data::Dumper; use Getopt::Long; my ( $ink , $int ); GetOptions( 'ink' => \$ink , 'int' => \$int ); print Dumper( $ink , $int );
    # perl x.pl -ink $VAR1 = 1; $VAR2 = undef; # perl x.pl -ink -int $VAR1 = 1; $VAR2 = 1;