There's really no need to accumilate all input =)

Let's go through three imaginary lists:

bar baz foo gorch ... baz foo fuzzy gorch ... bar bar bar gorch ...
process 1 gets the first line, and just prints that stream out.

Process 2 gets the output of process one, and it's own input.

So process 2 reads 'bar' coming from proc 1, and then reads a line from it's own input, and sees that it's 'baz'. Since 'baz' comes after 'bar', we know that we need to progress the first input, so we read another line from proc 1. We got 'baz'. So now we have 'baz' and 'baz'. We print that out, and continue. Then it reads 'foo' from process 1, and 'foo' from process two. That is also printed. Next come 'gorch' and 'fuzzy'. They aren't the same. since 'fuzzy' is alphabetically earlier than 'gorch', we read the next word from process 2's input. The next line is 'gorch'. Since 'gorch' eq 'gorch', we print that out too. And so on and so forth...

This process goes on infinitely. As much as process 3 likes to read from it.

process 3 does the same job, only the stream it sees is 'baz', 'foo', 'gorch' ..., that is, the list of matches from the previous runs.

The way it works is the same - it reads a line from the output of process 2 - 'baz', and a line from it's own input - 'bar'. 'bar' comes before 'baz', so we read more from process 3's input. it's 'bar' two more times, so we just keep on skipping. The next thing we find is 'gorch'. Since 'gorch' comes later than 'baz', we read from process 2's output instead of process 3's input - 'foo'. 'foo' lt 'gorch', so we skip more - 'gorch'. 'gorch' eq 'gorch' - that's the first match. We can stop now.

-nuffin
zz zZ Z Z #!perl

In reply to Re^5: sockets and such in Perl by nothingmuch
in thread sockets and such in Perl by scotchfx

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.