Howdy:

I have a hopefully easy problem. I am trying to isolate information between two patterns to both capture the information between (here, the case name) and count the instances a particular word (here, the word Education but I would also like to count the number of words in general). I am able to isolate the beginning pattern and the end pattern across multiple line but I can't figure out how to capture and count ALL of the this text between the patterns. When I run my script, I only capture the last matched line and only count the last instance. I am not able to manipulate the entire string of text across multiple lines between the established patterns.

This is my script:

my $casename = ''; my $count = 0; $/=""; # paragraph input mode while (<IN>) { if (/^\d+\sof\s\d+\sDOCUMENTS$/mx ... /^No.\s\w+$/mx){ if (/^(.*)/){ $casename=$1;} if (/EDUCATION/g){ $count++;} next;} } print "Case Name: $casename\n"; print "Education: $count\n";

Which does isolate the correct bounded text in a much larger file, as such:

97 of 141 DOCUMENTS HOKE COUNTY BOARD OF EDUCATION; HALIFAX COUNTY BOARD OF EDUCATION; ROBESON COUNTY BOARD OF EDUCATION; CUMBERLAND COUNTY BOARD OF EDUCA\TION; VANCE COUNTY BOARD OF EDUCATION; RANDY L. HASTY, individually and as guardian ad litem of Randell B. Hasty; STEVEN R. SUNKEL, individually and as guardian ad litem of Andrew J. Sunkel; LIONEL WHIDBEE, individually and as guardian ad litem of Jeremy L. Whidbee; TYRONE T. WILLIAMS, individually and as guardian ad litem of Trevelyn L. Williams; D.E. LOCKLEAR, JR., individually and as guardian ad litem of Jason E. Locklear; ANGUS B. THOMPSON II, individually and as guardian ad litem of Vandaliah J. Thompson; MARY ELIZABETH LOWERY, individually and as guardian ad litem of Lannie Rae Lowery; JENNIE G. PEARSON, individually and as guardian ad litem of Sharese D. Pearson; BENITA B. TIPTON, individually and as guardian ad litem of Whitney B. Tipton; DANA HOLTON JENKINS, individually and as guardian ad litem of Rachel M. Jenkins; LEON R. ROBINSON, individually and as guardian ad litem of Justin A. Robinson, Plaintiffs and ASHEVILLE CITY BOARD OF EDUCATION; BUNCOMBE COUNTY BOARD OF EDUCATION; CHARLOTTE-MECKLENBURG BOARD OF EDUCATION; DURHAM PUBLIC SCHOOLS BOARD OF EDUCATION; WAKE COUNTY BOARD OF EDUCATION; WINSTON-SALEM/FORSYTH COUNTY BOARD OF EDUCATION; CASSANDRA INGRAM, individually and as guardian ad litem of Darris Ingram; CAROL PENLAND, individually and as guardian ad litem of Jeremy Penland; DARLENE HARRIS, individually and as guardian ad litem of Shamek Harris; NETTIE THOMPSON, individually and as guardian ad litem of Annette Renee Thompson; OPHELIA AIKEN, individually and as guardian ad litem of Brandon Bell, Plaintiff-Intervenors v. STATE OF NORTH CAROLINA and the STATE BOARD OF EDUCATION, Defendants No. 530PA02

But, the returned information is as follows:

Case Name: No. 530PA02 Education: 2

Any idea what I am doing wrong? Thanks so much for your help! Can't tell you how much I appreciate it. Best, Michael


In reply to Capture/Counting text between patterns across multiple lines by micwood

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.