ovedpo15 has asked for the wisdom of the Perl Monks concerning the following question:
My script runs the some_job.pl -option1 --option2 --option3 part at some point. Before the GetOptions parse, I have the following code:my_script.pl --option1 --option2 --job some_job.pl -option1 --option2 +--option3
The code just saves everything after --job into the $opt{job} and removes it from the ARGV so GetOptions won't parse it. Now I noticed that if there is quotes inside the job part, it will remove those quotes. For example:my $job_flag = 0; foreach my $i (0..$#ARGV) { ​$opt{"job"} .= $ARGV[$i]." " if($job_flag); ​$job_flag = 1 if($ARGV[$i] =~ /^(\-\-|\-)job$/); ​undef $ARGV[$i] if($job_flag); }
Then the Dumper of ARGS is:my_script.pl --option1 --option2 --job some_job.pl -option1 'some_job2 +.pl -x abc' -option2
I would expect:$VAR1 = [ + + '--option1', '--option2', '--job', 'some_job.pl', '-option1', 'some_job2.pl -x abc', '-option2' ];
How can I know that there were quotes? I guess I'll need to think of another way to do this.$VAR1 = [ + + '--option1', '--option2', '--job', 'some_job.pl', '-option1', '\'some_job2.pl -x abc\'', '-option2' ];
2021-06-25 Athanasius fixed code tag.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: @ARGV ignores quotes (updated)
by AnomalousMonk (Archbishop) on Jun 19, 2021 at 17:56 UTC | |
Re: @ARGV ignores quotes
by NetWallah (Canon) on Jun 19, 2021 at 18:55 UTC | |
Re: @ARGV ignores quotes
by hrcerq (Monk) on Jun 19, 2021 at 21:37 UTC | |
by kcott (Archbishop) on Jun 19, 2021 at 23:28 UTC | |
by AnomalousMonk (Archbishop) on Jun 19, 2021 at 22:41 UTC | |
Re: @ARGV ignores quotes
by ikegami (Patriarch) on Jun 20, 2021 at 06:11 UTC | |
Re: @ARGV ignores quotes
by Anonymous Monk on Jun 20, 2021 at 06:44 UTC | |
by afoken (Chancellor) on Jun 20, 2021 at 09:47 UTC |