I'm not sure that I completely understand the context of your problem, but a few suggestions. Make a more general expression for the 'NAME: DATE' lines and capture into a hash. You have 4 regex lines to describe the filename, perhaps just one different regex would suffice? When you find the place after the FILENAME where the data capture is supposed to happen, sometimes it works out well to call a subroutine to finish that job off. Here is some code...
#!usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
$Data::Dumper::Sortkeys =1;
my %hash;
sub get_html
{
while (<DATA>)
{
if (/<html>/ .. /<\/html>/) ##see [id://525392]
{
chomp;
push @{$hash{DATA}},$_;
}
}
}
while (<DATA>)
{
if ( (my ($name, $date) = m/^\s*([\w ]+):\s+([\w-]+)/))
{
$hash{$name}=$date;
}
if (my ($filename) = m/^\s*<FILENAME>\s*(\w+ex(-)?21.*.htm)/i)
{
$hash{FILENAME}=$filename;
get_html();
}
}
print Dumper \%hash;
=Prints: *********
$VAR1 = {
'CENTRAL INDEX KEY' => '0000786368',
'CONFORMED PERIOD OF REPORT' => '20081231',
'DATA' => [
'<html>',
'blah ',
'smore blah',
'blahblah',
' **** BODY OF TEXT I WISH TO EXTRACT *****
+',
'</html>'
],
'DATE AS OF CHANGE' => '20090331',
'FILED AS OF DATE' => '20090331',
'FILENAME' => 'v144610_ex21.htm',
'FORM TYPE' => '10-K'
};
=cut
__DATA__
*********** Sample text ***************
CONFORMED PERIOD OF REPORT: 20081231 ------ individual
+line I want
FILED AS OF DATE: 20090331 ------ individual line I
+ want
DATE AS OF CHANGE: 20090331 ------ individual line
+I want
CENTRAL INDEX KEY: 0000786368 ------ individual line
+ I want
FORM TYPE: 10-K ------ individual line I want
Whole buncha text here …………….
</DOCUMENT>
<DOCUMENT>
<TYPE>EX-21
<SEQUENCE>7
<FILENAME>v144610_ex21.htm -----------My starting point
<TEXT>
<html>
blah
smore blah
blahblah
**** BODY OF TEXT I WISH TO EXTRACT *****
</html>
</TEXT>
</DOCUMENT> ----------- My ending point
**********End of sample text ***********
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.