Hi Perlmonks,

I'm Patrick, this is my first post.

Here is my situation:

I have a txt file where I'm trying to extract "Significant Accounting Policies" (SAP) from a 10k. There usually is a number to the left of SAP.

I would like to take that number and make it a variable then add 1 to that variable to identify the following section so then I can end the collection of the SAP. For example, if the number in front of SAP is 3, I would extract 3, create a variable, add 1, and my new variable would be 4. The code would then identify that the following section is section 4 and I can end my extraction at the beginning of section 4.

Here is an example:

(1) Summary of Significant Accounting Policies

Revenue Recognition

Revenue is recognized at the time goods are sold and shipped.

(2) Long-term Debt

****

the number in front of SAP is not always the number 1 and the following item is not always long-term debt.

#!/usr/bin/perl -w #use strict; # This program extracts data from an SEC filing, including chunks of t +ext use Benchmark; #get the HTML-Format package from the package manager. use HTML::Formatter; #get the HTML-TREE from the package manager use HTML::TreeBuilder; use HTML::FormatText; $startTime = new Benchmark; #This program is written to obtain "Significant Accounting Policies" w +hich are typically found in item 4/4 of the 10k my $startstring='((^\s*?)Significant Accounting Policies\s\n)'; #Specify keywords/phrases you expect to find within the item (make sur +e the words phrases are not also in the start or end string) my $keywords='(estimates|Financial Accounting Standards Board|Reven +ue Recognition|generally accepted accounting principles|accruals|inve +ntories|straight-line|)'; #horizontal line means alternative match if + not found #Specify the end of the text you are looking for. # Need to create a flexible end string that uses +1 the variable in fr +ont of "SAP" my $endstring='((^\s*?)Item\s+(10)[\.\-]?[^\d]*?\n)'; my $direct="D:\\ExternalFiles\\Edgar\\tenks\\randomsort";

In reply to Making a variable from a number in front of a string by porsche5k

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.