Dear Monks, I'm just trying to put together a small prototype for some fun and learning on text mining/parsing but I've come a cropper on regexing a larger block that I normally do (usually simple finding tasks or look ahead/look behind). I've got a series of texts where the only common point is
Sidenote: <blah> at the beginning of each text which I want to use as the splitting point so that I can turn the whole file into a series of xml objects (in due course) to use later.
When I print out I get
but I had thought that a pattern match as above would give me everything starting with [Sidenote: in one div then start a new div for the next [Sidenote: but clearly there is something that I have misunderstood in the tutorials.
use strict;
use warnings;
my $text = "C:\\letters.txt";
my @letters;
open(IN, $text) || die "Can't open $text";
@letters = <IN>;
close(IN);
chomp @letters;
foreach my $indiv_note (@letters) {
my $letter_text = ($indiv_note =~ /(^\[Sidenote (?: (?!^\[Sidenote).
+ )* )/);
print "<div>$letter_text</div>\n";
}
The sort of data that I using is:
[Sidenote: The same.]
_Sunday Evening._
* * * * *
I have at this moment got Pickwick and his friends on the Rochester
coach, and they are going on swimmingly, in company with a very
different character from any I have yet described, who I flatter mysel
+f
[Sidenote: Miss Hogarth.]
FURNIVAL'S INN, _Wednesday Evening, 1835._
MY DEAREST KATE,
The House is up; but I am very sorry to say that I must stay at home.
+I
have had a visit from the publishers this morning, and the story canno
+t
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.