in reply to Newbie: Pipe/STDIN Clarification

See perlintro/perlopentut, basically
open my($out), 'command |' or die $!; print $out $_ while <$in>; close $out;

Using system can be ok :) system "command < file";

Replies are listed 'Best First'.
Re^2: Newbie: Pipe/STDIN Clarification
by graff (Chancellor) on Nov 05, 2011 at 13:41 UTC
    That open statement has things the wrong way around. To open a file handle for printing to a pipeline command, it goes like this:
    open my $fh, '| command' or die $!;
    Or better yet, use the 3-arg open call -- and while we're at it, let's provide the command as an array, and get the process-ID:
    my @command = qw/downstream_process -a option1 -b option2 -etc/; my pid = open( my $fh, '|-', @command ) or die $!;
    (The form of open call shown by AnonyMonk would be for running a command so that you can read its output, and you wouldn't write to that file handle.)