in reply to Running a string through a filter program and recieving the output as a string

Here's a basic outline -- you might want to modify the split line.
open FILE, "<", $file; while(<FILE>); chomp; my @words = split; foreach my $word ( @words ){ # my $newword = `sed $word`; # UPDATE: original lazy typing my $newword = `echo $word | sed`; # UPDATE: more realistic print $newword, "\n"; } } close FILE;
What exactly is the tr/sed command doing? I suspect that there's a native perl way to do it (e.g. see perldoc -f tr).

As for using pipes instead of backticks, see the Tutorials and perlipc ...

Update: changed the backtick command .. i was just lazy the first time :)

Replies are listed 'Best First'.
Re^2: Running a string through a filter program and recieving the output as a string
by Skeeve (Parson) on Sep 30, 2005 at 05:35 UTC
    That's it almost. By saying "filter program" I think the OP means the words have to be piped to the filter program. Filters usually take STDIN as input.

    Also, from the description of the OP I assume his program will deal with different filters, set by (e.g.) commandline parameters.

    So
    my $newword = `sed $word`;
    should become
    my $newword = `echo '$word' | $filterprogram`;
    Where $filterprogram has to be set somewhere else in the script.

    $\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print
Re^2: Running a string through a filter program and recieving the output as a string
by pg (Canon) on Sep 30, 2005 at 03:10 UTC
    "What exactly is the tr/sed command doing?"

    From unix man page, in a nut shell:

    "Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sed's ability to filter text in a pipeline which particularly distinguishes it from other types of editors."
    "The tr utility copies the standard input to the standard output with substitution or deletion of selected characters. The options specified and the string1 and string2 operands control translations that occur while copying characters and single-character collating elements."
      I think he meant in this case specifically, since Perl can do tr and sed tasks quite easily.
        Actually I just used tr and sed as examples. I want to use a different filter program but similar in that it takes input as stdin and outputs to stdout.