some perl questions

H

Huub

Hi,

Since I didn't find the answers in the FAQ's:
- is it possible to use reg.exp. for searching through (Windows)
directories?
- is it possible to look into Word docs?

If the answer happens to be in the FAQ, please direct me there. If not,
help is appreciated.

Thanks

Huub
 
J

John Bokma

Huub said:
Hi,

Since I didn't find the answers in the FAQ's:
- is it possible to use reg.exp. for searching through (Windows)
directories?
http://search.cpan.org/~rclamp/File-Find-Rule-0.28/lib/File/Find/Rule.pm

- is it possible to look into Word docs?

With OLE you might be able to load a Word doc into Word, and "look into
it". Easier ways might be possible depending on what you want to look for.

There are applications written that do the above for you though.
 
H

Huub

J

John Bokma

Huub said:
Thank you.


Is this also possible wit Java/JPL or is this asking for a lot of
trouble?

I can't answer that one (also this is a Perl group, but you might be
lucky).
I guess those aren't open-source?

The ones I know: no. They do however an excellent job of finding
documents on your harddisk. It depends a lot on what you want to do. If
you want to do searches inside Word documents, pfft. I guess it's
possible to find a specification online somewhere. But I couldn't find a
Perl module that can read Word. The only other option I could think of
was using OLE, but that is slow, and probably a lot of work to get
right.
 
U

usenet

John said:
Impressive, otoh, it looks a bit like:

use PHP;

The resemblance escapes me... it's more like Ruby (forget I said that).
Also error handling is not quite clear...

The module provides default basic error-handling (prints an error
message with $!), so if that's all you want, you don't need to pepper
your statements with qq[ || die "oh no - $!\n" ]. You may stipulate
your own error subroutine (by reference) when you create an io object.
Of course, if you define custom __WARN__ or __DIE__ handlers, the
module's basic error reporting will use those whenever it warn()s or
die()s, so that's a 'backdoor' way to define your own error handling.
 
A

A. Sinan Unur

But I couldn't find a Perl module that can read Word.
The only other option I could think of was using OLE,
but that is slow, and probably a lot of work to get
right.

There is a fair bit of trial-and-error involved, and it has the drawback
of only working on a Windows machine with Office installed, but here is
something that might help the OP get started:

#!/usr/bin/perl

use strict;
use warnings;

use Win32::OLE;
$Win32::OLE::Warn = 3;
use Win32::OLE::Enum;

use FindBin qw( $Bin );
use File::Spec::Functions qw( catfile canonpath );

my $word;
eval {
$word= Win32::OLE->GetActiveObject('Word.Application')
};
die "Word not installed" if $@;

unless (defined $word) {
$word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit })
or die "Cannot start Word";
}

my $doc = $word->Documents->Open(canonpath(catfile $Bin, 'test.doc'));
my $par = $doc->Paragraphs;
my $iter = Win32::OLE::Enum->new($par);

while(defined(my $paragraph = $iter->Next)) {
print $paragraph->{Range}->{Text}, "\n";
}

__END__
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,175
Messages
2,570,946
Members
47,497
Latest member
PilarLumpk

Latest Threads

Top