Also, I found out that I can use '--' option. But it really feels to me as a workaround and I don't want to make the users use it.
I don't think it's a workaround, using -- to indicate "stop processing options here" is a really common thing - perl, git, GNU getopt, and many other tools do it, which is why Getopt::Long supports it.
I also don't think messing with @ARGV is a bad thing to do, especially since you'd just be looking for a fixed string.
use warnings; use strict; use List::Util qw/first/; @ARGV = qw/create --folder empty --size 50 --additional hey how ---are --you 555/; my $i = first { $ARGV[$_] eq '--additional' } 0..$#ARGV; my (undef,@add) = defined $i ? splice @ARGV, $i, $#ARGV-$i+1 : (); use Data::Dump; dd \@ARGV, \@add; __END__ ( ["create", "--folder", "empty", "--size", 50], ["hey", "how", "---are", "--you", 555], )
Admittedly not the most beautiful code, but it works. If you want more elegance, I'd suggest either -- or hippo's suggestion...
In reply to Re: GetOpt unknown args
by haukex
in thread GetOpt unknown args
by ovedpo15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |