Here's another step along the way. Based on tybalt89's beginning. Handles arbritrary nesting levels (I think). (Update: Does not handle arbitrary nesting levels of identical switches. E.g., change  -fizz_boff ... -fizz_boff- to  -tex_args ... -tex_args- in the example code below. (sigh)) Lots of assumptions about syntax of the c.l. This needs more testing, and I'm sure proxie will be back with lots of updated and expanded specifications.

use 5.014; # needs /r modifier for s/// (also uses 5.10+ \K) use warnings; use strict; use Data::Dump qw(pp); my $cl = q(execute test_number_1 -tex -tex_args -sub_args +debug_dir=. +/ -fizz_boff -sub_args +debug_dir=./ -constraint parity_en,random_en +-sub_args '"' ruck=1 '"' -bar -xyzzy -bar- -constraint dual_en +-sub_args -cd -sub_args 2596.slow -fizz_boff- -sub_args test -seed 1 +-tex_args- -opt 1 -foo -x y -zz 42 -foo- -tag 2 -last 1); print qq{>$cl< \n\n}; my $in = ' '; # indentation for each level of nesting my $rin = qr{ \Q$in\E }xms; # regex for 1 indent level my $clump = qr{ (?: -sub_args \s+ \S+ | \S) .*? (?= \s+ - | \Z) }xms; my $answer; $answer .= s/^-/$in-/gmr . qq{\n} for $cl =~ m{ $clump }xmsg; # ok pp $answer; print "\n\n"; 1 while $answer =~ s{ (^ ($rin+) - [^\n]+) \n \K ((?: ^ \2 - [^\n]+ \n)*?) (?= ^ \1 -) } { $3 =~ s{^}{$in}xmsgr }xmsge; print qq{>>>$answer<<< \n\n};
Output:
c:\@Work\Perl\monks\proxie>perl prettyprint_cl_1.pl >execute test_number_1 -tex -tex_args -sub_args +debug_dir=./ -fizz_bo +ff -sub_args +debug_dir=./ -constraint parity_en,random_en -sub_args +'"' ruck=1 '"' -bar -xyzzy -bar- -constraint dual_en -sub_args +-cd -sub_args 2596.slow -fizz_boff- -sub_args test -seed 1 -tex_args- + -opt 1 -foo -x y -zz 42 -foo- -tag 2 -last 1< "execute test_number_1\n -tex\n -tex_args\n -sub_args +debug_ +dir=./\n -fizz_boff\n -s ub_args +debug_dir=./\n -constraint parity_en,random_en\n -sub_a +rgs '\"' ruck=1 '\"'\n -bar \n -xyzzy\n -bar-\n -constraint dual_en\n -sub_args -cd\n + -sub_args 2596.slow\n -f izz_boff-\n -sub_args test\n -seed 1\n -tex_args-\n -opt 1 +\n -foo\n -x y\n -zz 42\n -foo-\n -tag 2\n -last 1\n" >>>execute test_number_1 -tex -tex_args -sub_args +debug_dir=./ -fizz_boff -sub_args +debug_dir=./ -constraint parity_en,random_en -sub_args '"' ruck=1 '"' -bar -xyzzy -bar- -constraint dual_en -sub_args -cd -sub_args 2596.slow -fizz_boff- -sub_args test -seed 1 -tex_args- -opt 1 -foo -x y -zz 42 -foo- -tag 2 -last 1 <<<
Sorry about any wraparound.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Help with parsing command line to make more readable (updated) by AnomalousMonk
in thread Help with parsing command line to make more readable by proxie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.