use warnings; use strict; # we are going be working with MS Word Objects use Win32::OLE qw(in with); # some sites advise me to use these but I am not sure # why we need them and can't really understand # win32::OLE. If there is a way to decipher them I am happy # to know # use Win32::OLE::Const 'Microsoft Word'; # use Win32::OLE::Enum; use CGI; # we'll be having some HTML writing my $text = ""; my $directory = "../sample_folder"; opendir (DH, $directory) || die "can't opendir $directory: $!"; # test whether the item returned by grep is a file and its name does not start with "_" # because there is one redirect input which start with "_" my @dir_list = grep { (/^EN-US_.+/) && -d "$directory/$_" } readdir(DH); # we are working with Word application my $Word = Win32::OLE->new('Word.Application', 'Quit'); my $root = "C:\\Documents and Settings\\parent_folder"; foreach (@dir_list){ # extract the language abbreviation m/^EN-US_(.+)$/i; my $doc = "$root\\EN-US_$1\\sample_doc.doc"; $Word->Documents->Open("$doc") || die("Unable to open $doc ", Win32::OLE->LastError()); $Word->{Visible}= 0; # we don't need to see Word in an active window # get the first table my $table = $Word->ActiveDocument->Tables(1); # $table -> Select(); # do I need to select? $text = $table->Cell(1,1)->Range->{Text}; print "*$text*"; #my $language = lc($1); # Prepare OUT_FOOTER file #open(OUT_FOOTER, "> $directory/updates/footer_$language.html") || die("can't open $directory/updates/footer_$language.html for writing: $!"); # close document and Word instance print "Closing document and Word\n"; $Word->ActiveDocument->Close(); close OUT_FOOTER; } $Word->Quit; closedir DH;