I need to parse word tables in .doc format. Need some help with regex.

I get a dump of the table and the number of columns (first row is header) with:

use strict; use warnings; require Text::Extract::Word; Text::Extract::Word->import( qw(get_all_text) ); my $InputFileReadable ='Fish.doc'; my $content = get_all_text($InputFileReadable); #detecting structure my ($header, $body)= split /(\a)\1+/, $content; my $NrColumns = () = $header =~ /\a/g; $NrColumns++; print $NrColumns;

Now I need to parse $content. I now that columns are separated by \a (BEL) and end of rows by \a\a. Simply splitting $content everytime I match \a\a is not enough, since if a column is empty I will have \a\a also as non end-of-row delimiter. So, I need to keep track that \a\a is matching only at $NrColumns positions.

Agreement(BEL)ACAP(BEL)ACAP(BEL)Accord(BEL)(BEL)albatross(BEL)(BEL)(BE +L)albatros(BEL)(BEL)alleged violation(BEL)(BEL)(BEL)infraction présum +ée(BEL)(BEL)allowable(BEL)(BEL)(BEL)admissible(BEL)(BEL)anchovy(BEL)( +BEL)(BEL)anchois(BEL)(BEL)angler fish, burbot(BEL)(BEL)(BEL)lotte(BEL +)(BEL)

With $NrColumns = 4 I should get:

Agreement(BEL)ACAP(BEL)ACAP(BEL)Accord(BEL)(BEL) albatross(BEL)(BEL)(BEL)albatros(BEL)(BEL) alleged violation(BEL)(BEL)(BEL)infraction présumée(BEL)(BEL) allowable(BEL)(BEL)(BEL)admissible(BEL)(BEL) anchovy(BEL)(BEL)(BEL)anchois(BEL)(BEL) angler fish, burbot(BEL)(BEL)(BEL)lotte(BEL)(BEL)

In reply to parsing table .doc by IB2017

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.