If what you meant by indexing is grabbing each word in a Word Document and creating an index of those words to find them later, the following will give you all of the words in a document. I'll let you focus on the indexing part. :)
#!/usr/bin/perl
# general use directives
use strict;
use warnings;
# project specific use directives
# this comes with the standard ActiveState
# distribution. You can also look for
# a newer version with PPM
use Win32::OLE;
my $wd;
# get the document
# use the full path
eval
{
$wd = Win32::OLE->GetObject('C:/pathto/document/foo.doc')
};
die "Unable to load document\n" if $@;
# all of the Word document data members I'm using
# are explained in the MSDN documentation of the
# external interfaces of a Word Document.
# if you have MSDN, search for "Word OLE".
# get the number of paragraphs
my $paraCount = $wd->{Paragraphs}->Count;
# set the counter
my $foo = 0;
my @words;
while ($foo++ < $paraCount)
{
push @words, split /\s/, $wd->{Paragraphs}{$foo}{Range}{Text};
}
#clean up at the end
undef $wd;
That's how you get the words of a word document out and into an array. You may prefer a different data structure, but again, I'll leave that up to you! I hope this helps.
-
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.
|