#!/usr/bin/perl use strict; use warnings; use Getopt::Long qw( :config posix_default gnu_compat bundling no_auto_abbrev no_ignore_case ); my $column=1; @ARGV = grep $_ !~ /\A--c\b/, @ARGV; #if( grep s/\A--c\b=?.*//, @ARGV ){ $column = 100 }; # \b can be replaced with (?!o) for finer resolution #if( grep s/\A--c(?!o)=?.*//, @ARGV ){ $column = 100 }; GetOptions( 'column|c=i' => \$column, ) or die; print "\$column is $column\n"; die if $column < 1; __END__ # grep filtered $ ~/Desktop/gol.pl --c 2 --c=2 --c= 2 --c = 2 $column is 1 # grep substitution conditional $ ~/Desktop/gol.pl --c= 2 --c = 2 --c 2 --c=2 $column is 100 #### #!/usr/bin/perl # first attempt, non-working as the # long option is also discounted use strict; use warnings; use Getopt::Long qw( :config posix_default gnu_compat bundling no_auto_abbrev no_ignore_case ); my $column = 1; #print map "[$_]", @ARGV, "\n"; #exclude the unwanted format with a filtering grep @ARGV = grep $_ !~ /\A--c=/, @ARGV; # remove the offending format using substition operator and test to see if you did # if( grep s/\A--c=.*//, @ARGV ){ $column = 100 }; #print map "[$_]", @ARGV, "\n"; GetOptions( 'column|c=i' => \$column, ) or die; print "\$column is $column\n"; die if $column < 1; __END__ $ ~/Desktop/gol.pl --column=2 $column is 2 $ ~/Desktop/gol.pl -c2 $column is 2 $ ~/Desktop/gol.pl --c=2 $column is 1 $ ~/Desktop/gol.pl -c=2 Value "=2" invalid for option c (number expected) Unknown option: = Unknown option: 2 Died at ~/Desktop/gol.pl line 19. # using grep and substitution as conditional $ ~/Desktop/gol.pl --c=2 $column is 100 #but also doesnt allow $ ~/Desktop/gol.pl --column 2 $column is 1