Hi Monks,
I have a question about inserting characters into strings. Before anyone says RTFAQ or some such, this is a bit different than the question or 2 I've found in the Q&A...
I have an array of strings of text, mostly UPPERCASE, with intermittent lowercase html tags. I want to insert a space after every 10th UPPERCASE letter, and a newline (and/or html-br) after every 100th, regardless of how many other characters are interspersed between them.
My first thought was something like:
@space = #some array of long text strings;
$n = () = @space;
$i = 0;
while ($i < $n) {
$space[$i] =~ s/([A-Z]{10}?)/$1 .' '/gxe;
$i++;
}
And that works great, when there are 10 UPPERCASE in a row, but not when there is any lowercase or brackets separating them. Then I tried some cocamamie bit where I was counting and incrementing after every instance of an uppercase, but I wound up trying to write to $1, which I know is read only.
Can anyone enlighten me on a way to accomplish this?
Thanks,
Matt
-
--
Matt Dunn - mdunn@stwing.org
http://www.stwing.org/~mdunn/
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.