Re: How do I output an array twice via pipe instead of only once?
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 30 Jan 2007 09:55:09 -0800
On Jan 30, 12:13 pm, junk2j...@xxxxxxxxxxx wrote:
I have a script that outputs an array which gets used as input in a
second script. The problem is that if I want to send over a second
array, my script sends them both over at the same time. It seems like
perl is trying to be too efficient. Here are the simplified scripts:
#!/usr/bin/perl
#
# a.pl
#
open(OUTPUT,"|b.pl");
@array1=("A","B");
print OUTPUT @array1;
@array2=("C","D");
print OUTPUT @array2;
---------------------------------------------------
#!/usr/bin/perl
#
# b.pl
#
@input=<STDIN>;
print "here is the inputted array: @input \n";
-----------------------------------------------------
What the script displays is:
here is the inputted array: ABCD
-----------------------------------------------------
But what I want is:
here is the inputted array: AB
here is the inputted array: CD
You've got your problem backwards. It is not the fault of what's
being sent, but of what's being read. When you use the standard
<STDIN> operation, you are telling Perl to read until the next
newline. You did not send any newlines in the first send, so Perl
keeps waiting until it does receive a newline (or it receives end-of-
file, which happens when a.pl closes, thereby closing the pipe to
b.pl).
Either change your read to only read two characters at a time (see
perldoc -f read), or change your printing to send newlines after each
send.
Paul Lalli
.
- Follow-Ups:
- Re: How do I output an array twice via pipe instead of only once?
- From: Paul Lalli
- Re: How do I output an array twice via pipe instead of only once?
- References:
- How do I output an array twice via pipe instead of only once?
- From: junk2junk
- How do I output an array twice via pipe instead of only once?
- Prev by Date: How do I output an array twice via pipe instead of only once?
- Next by Date: Re: How do I output an array twice via pipe instead of only once?
- Previous by thread: How do I output an array twice via pipe instead of only once?
- Next by thread: Re: How do I output an array twice via pipe instead of only once?
- Index(es):
Relevant Pages
|