Have you tried use re 'debug';
Yes. But it didn't help. It shows that matches do occur; but doesn't explain why the newlines are never inserted.
It seems your example data miss a digit at the end of each number.
My mistake trying to simplify the data. Two corrections are possible:
- Remove one \d from each side of the regex:
while( <DATA> ) {
s[\s(\d+)\d\K\s(?=(\d+)\d\s)]{
print "$1:$2";
$1 + 1 == $2 ? "\n" : ' '
}ge;
print;
}
- Add a digit to the end of each number in the data:
1051 1061 1071 1081 1091 1101 1111 1121 1131
11151 11161 11171 11181 11191 11201 11211 11221 11231
123451 123461 123471 123481 123491 123501 123511 123531
as you know what the regex should do
The idea of the regex is to match each pair of numbers in a line and capture the first d-2 digits of each number.
Eg. Match the pair and capture the first two digits of each: (10)91 (11)01.
Then if $1+1 (10+1) == $2 (11) replace the space between them with a newline.
The \K prevents the number before the replaced space being replaced. And the lookahead prevents the number after ebing replaced.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
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.