Sometimes you want to explicitly show the logic used to deconstruct and reconstruct things:
$str = 'command1 command2 command3 "command4 --some-arg arg --some-oth
+er-arg 2" command5';
@words = split(/\s/, $str);
$arg_flag = 0;
for $i (0 .. $#words) {
if ($words[$i] =~ /\"/) {
if ($arg_flag == 0) { #starting a new command with args
$arg_flag = 1;
$words[$i] =~ s/\"//;
$this_command = $words[$i];
}
else { #ending a new command with args
$words[$i] =~ s/\"//;
$this_command .= " ".$words[$i];
push (@commands, $this_command);
$arg_flag = 0;
}
}
else {
if ($arg_flag == 0) { #any old command
push (@commands, $words[$i]);
}
else { # an arg in a command being built
$this_command .= " ".$words[$i];
}
}
}
It's clunky, but it works, and it preserves the logic for future generations to understsand.
Forget that fear of gravity,
Get a little savagery in your life.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.