IB2017 has asked for the wisdom of the Perl Monks concerning the following question:
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)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: parsing table .doc
by tybalt89 (Monsignor) on May 31, 2020 at 14:42 UTC | |
Re: parsing table .doc
by kcott (Archbishop) on Jun 01, 2020 at 08:49 UTC | |
Re: parsing table .doc
by IB2017 (Pilgrim) on May 31, 2020 at 11:12 UTC | |
Re: parsing table .doc
by perlfan (Parson) on May 31, 2020 at 10:15 UTC | |
by marto (Cardinal) on May 31, 2020 at 10:23 UTC | |
by IB2017 (Pilgrim) on May 31, 2020 at 10:25 UTC |