Well, now you're still just being too vague. Does this "different" filter program depend critically on reading exactly one word per run? If so, I think you should look for a better implementation of whatever this program does.

If, like most well-written filter programs, it accepts a stream of one or more lines of text, does its work one line at a time, and outputs each line as it finishes, then you can easily set up a process using Perl to feed it and collect its output for further operations. In this case, it's just a matter of making sure you feed it properly.

For example, if it accepts one word per line, does some transformation and outputs a line of data for each input word, then a perl snippet like this would be one "easy" way to handle the job for a given data file:

# open a pipeline in which a perl one-liner feeds # word-tokenized data from $file to "word_filter"; # the FILT file handle is then used to read the output # of word_filter (one line per word): open( FILT, "perl -pe 's/^\\s*//; s/\\s+/\\n/g' $file | word_filter |" + ) or die "subshell: $!"; ## note the "\\" in the one-liner while (<FILT>) { # $_ holds one line of output from "word_filter" # so do something with that... }

In reply to Re^5: Running a string through a filter program and recieving the output as a string by graff
in thread Running a string through a filter program and recieving the output as a string by bwgoudey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.