Here's the basics:
use strict;
# This turns off output buffering, so output is immediate.
$| = 1;
# Load Wordnet
use WordNet::QueryData;
# Adjust location as needed
my $wordnet = WordNet::QueryData->new("wordnet.db");
# This reads lines from STDIN. If there is no input,
# it waits.
while (my $input = <>) {
# Remove the newline from the end
chomp $input;
# Here we have to think about a protocol.
# I suggest something of the form command;arg1;arg2
my ($command, $arg1, $arg2) = split ';', $input;
my @results;
# Dispatch based on command
if ($command eq 'quit') {
exit;
} elsif ($command eq 'word') {
# Do a WordNet queryWord
@results = $wordnet->queryWord($arg1, $arg2);
} elsif ($command eq 'sense') {
@results = $wordnet->querySense($arg1, $arg2);
} else {
die "Unknown command $command";
}
# OK, send the results back out over STDOUT
my $line = join ',', @results;
print $line . "\n";
}
Now then, that's the Perl side. You can test it from the command line like this (if you saved it in wordnet-ipc.pl):
perl.exe wordnet-ipc.pl
It should appear to "hang", but really it's just waiting on your input. Try typing
sense;run#v. To exit, type
exit.
The part I'm still fuzzy on is how to start up a process from VBA and get stream objects on it's input and output. I'm on a linux box now, so I don't have access to my VBA docs. I'll try to have a shot at it when I get home.
--Clinton