$answer .= s/^-/\t-/gmr . "\n" for /\S.*?(?= +-)/g;
This leaves out the -tag 2 at the very end of the c.l. string. Changing the look-ahead to (?=(?: +-|$)) fixes this:
I still don't like that the -cd is separated from its preceding -sub_args argument. Have to think about that...c:\@Work\Perl\monks>perl -wMstrict -le "$_ = q(execute test_number_1 -tex -tex_args -sub_args +debug_dir=./ - +sub_args +debug_dir=./ -constraint parity_en,random_en -sub_args '\"' + ruck=1 '\"' -constraint dual_en -sub_args -cd -sub_args 2596.slow -s +ub_args test -seed 1 -tex_args- -opt 1 -tag 2); ;; print qq{$_ \n}; ;; my $answer = ''; $answer .= s/^-/\t-/gmr . \"\n\" for /\S.*?(?=(?: +-|$))/g; $answer =~ s{^(\s*)(-\w+)\n\K((?:.*\n)*?)(?=\1\2-\n)} { $3 =~ s{^}{\t}gmr }gem; ;; print $answer; " execute test_number_1 -tex -tex_args -sub_args +debug_dir=./ -sub_args + +debug_dir=./ -constraint par ity_en,random_en -sub_args '"' ruck=1 '"' -constraint dual_en -sub_arg +s -cd -sub_args 2596.slow -sub_args test -seed 1 -tex_args- -opt 1 -t +ag 2 execute test_number_1 -tex -tex_args -sub_args +debug_dir=./ -sub_args +debug_dir=./ -constraint parity_en,random_en -sub_args '"' ruck=1 '"' -constraint dual_en -sub_args -cd -sub_args 2596.slow -sub_args test -seed 1 -tex_args- -opt 1 -tag 2
Give a man a fish: <%-{-{-{-<
In reply to Re^2: Help with parsing command line to make more readable
by AnomalousMonk
in thread Help with parsing command line to make more readable
by proxie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |