update: it appears that I didn't understand all the requirements when I wrote this code. But hopefully it will help you in your endeavor. This shows how to get all of the comment blocks. From what I understand there is a single =Additional Notes= section at the very end. Make a 2nd regex along the same line of thought as below to get that section, but since it is the very last section, then terminator is not needed, eg.
m/[=]+Additional Notes[=]+.*?\n(.*)/s; #this (.*) will get all
#to end of the $page
#see below, ending [=]+ and /g
+is not
#needed for this job
#!/usr/bin/perl -w
use strict;
open (IN , '<', "awebpage.txt") or die;
my @page = <IN>; #this is like a "slurp" into a scalar
my $page = join('',@page); #with undef record seperator
my @comments = $page =~ m/[=]+Comments[=]+.*?\n(.*?)[=]+/gs;
my $count =1;
foreach (@comments)
{
print "COMMENT #$count is:\n$_";
$count++;
}
=file awebpage.txt is:
A webpage.
===Comments===
This webpage contains information bla bla bla
=Section 2=
Some more text here.
whatever
===Comments===
Some other comments here.
=Another section=
=Aditional Notes=
=Comments=
some more comments and notes here
=Notes=
More notes here.
=cut
=****prints:****
COMMENT #1 is:
This webpage contains information bla bla bla
COMMENT #2 is:
Some other comments here.
COMMENT #3 is:
some more comments and notes here
=cut
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.