0

I'm currently trying to take my program and have it take user input, usually a text file then call an external script to count the words. The script I'm working on is essentially a "middle man" and I'm trying to get more familiar with piping to external scripts/commands. It's currently not correctly executing the word counter script. Here's the code:

I'm still receiving error for ./word_counter.pl saying "no such file or directory at glue.pl (which is this script you see here)".

#!usr/bin/perl
use warnings;
use strict;
use IO::Handle qw();

open (PIPE_TO, "|-", "./word_counter.pl");
While(<>)
{
$PIPE_TO -> autoflush(1);
print PIPE_TO $_;

}
1
  • 2
    Getting rid of the obvious syntax errors would be a start. Commented Apr 3, 2013 at 4:41

3 Answers 3

1

Suffering from buffering?

use IO::Handle qw( );
PIPE_TO->autoflush(1);
Sign up to request clarification or add additional context in comments.

Comments

0

The reason it doesn't work is probably that you have syntax errors.

Otherwise: Other than introducing line-buffered semantics, you are really doing nothing here (you just pipe what you read to another program, which is in this case equivalent to just running the program)

Modulo the buffering (which you don't seem to explicitly need) an equivalent script would be:

#!/usr/bin/perl

exec ("./word_counter.pl");

2 Comments

Is there anyway to use the | syntax so this executes?
In you current OP, you need to remove the trailing / from #!/usr/bin/perl/, and you need to close the paren in while (<STDIN>
0

Is this what you are trying to do?

#!/usr/bin/perl
use warnings;
use strict;

open (my $PIPE_TO, "|-", "./word_counter.pl") or die $!;
while(<>) {
  print $PIPE_TO $_;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.