Talking from a unix point of view, I have to ask for yet a little more clarification on this point:

I have a program that wants to read two separate streams from STDIN.

In unix, a data file is also referred to as a "stream". Since your example just uses  while <>, I wonder if you're talking about a case where two files (streams) are being presented to the script via ARGV, like this:

some_script.pl file1 file2
If that is what you mean, then you just need to study the explanation given by "perldoc -f eof", which includes the following:
In a "while (<>)" loop, "eof" or "eof(ARGV)" can be used to detect the end of each file, "eof()" will only detect the end of the last file. Examples: ...
An example relevant to your post would be:
my $prefix = 1; while (<>) { print "$prefix: $_"; $prefix++ if ( eof ); }
The only other situation I can imagine for the "two streams on STDIN" would be something like this:
cat file1 file2 | some_script.pl # or something less mundane: grep "target string" file1 | cat - file2 | some_script.pl
Of course, the whole point of the unix "cat" command is to concatenate two or more streams into a single stream, so in cases like this, the perl script is really only getting one stream, and unless there are reliable clues in the data content to indicate the different sources, the script will have no basis for telling one source from another -- it really is just one stream to the perl script, and there's no way around that.

(update: I should say, the only way around that is to make sure there are reliable clues in the resulting stream -- e.g.:

echo "____STREAM_BOUNDARY____" > bndry grep "target string" file1 | cat - bndry file2 | script.pl
and you fix script.pl so that it knows to look for the specific string that flags the stream boundary.)

In the earlier case, where the script is given two or more file names in @ARGV, and these are read successively by the diamond operator, perl obviously knows when one file ends and the next must be opened, and "eof" is how you find out about that.

If your notion of "two streams on STDIN" is referring to something other than these cases, then I'm puzzled as to what you could be talking about.


In reply to Re: what is EOF and how can I send it? by graff
in thread what is EOF and how can I send it? by revdiablo

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.