To explain the first response syntax:
#declarations
my ($quote_on,$output);
#default scalar is the data
$_ = q/this is a "test of some regexp" blah blah
this is another "test of some regexp" foo bar/;
#using $_ begin a for loop performing a split on each #element
for (split //) {
#quote_on is a boolean set to true when the increments reach
#a quote (and then off again when reaching another quote)
$quote_on = ($quote_on ? 0 : 1) if (/\"/);
#if processing elements after a quote, then replace the
#whitespace with an underscore
s/\s/_/g if $quote_on;
#assign all that to $output
$output .= $_;
}
I didn't write the original post, but I was thinking about doing it a different way, although this one seems to be
perfectly adequate and more importantly, maintainable, than a seemingly more elegant one-liner. Just IMHO
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.