Hi --
I've never used Perl for anything pipe-like before. The following is my attempt, running on Activestate 5.8.0 on WinXP. The code below is a framework, not my full-blown module.
I found the perl docs hard to understand for IPC::Open3. The following rough hackish code works but I'd like any comments on how I could be doing it better.
Should I be checking that the pipe opened? If so how? Should I have error checking elsewhere? Should I be closing the pipe gracefully, rather than killing it? And am I killing it correctly?
Thanks for helping me learn--
rkg
package Word::Spell;
use strict;
use warnings;
use lib qw(c:\ blah blah blah blah);
use base qw(Exporter);
our @EXPORT_OK = qw(spell);
use IPC::Open3;
my ($pid, $wph, $rph, $eph);
BEGIN {
my $cmd = 'c:/apps/aspell/bin/aspell';
my $args = '-a'; #-pipe --ignore-case --sug-mode=normal';
$pid = open3($wph, $rph, $eph,$cmd, $args);
# eat and confirm the id line
my $idline = <$rph>;
die "bad idline: $idline" unless $idline =~ /Aspell 0.50.3/;
}
sub spell {
my ($word) = @_;
die "word '$word' has spaces" if $word =~ /\s/;
die "word '$word' has numbers" if $word =~ /\d/;
die "word '$word' has odd chars" if $word =~ /[^A-Z-]/i;
print $wph "^$word\n";
my $result = <$rph>;
return $result;
}
END {
kill 9, $pid;
}
1;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.