in reply to what is EOF and how can I send it?
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:
If that is what you mean, then you just need to study the explanation given by "perldoc -f eof", which includes the following:some_script.pl file1 file2
An example relevant to your post would be: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: ...
The only other situation I can imagine for the "two streams on STDIN" would be something like this:my $prefix = 1; while (<>) { print "$prefix: $_"; $prefix++ if ( eof ); }
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.cat file1 file2 | some_script.pl # or something less mundane: grep "target string" file1 | cat - file2 | some_script.pl
(update: I should say, the only way around that is to make sure there are reliable clues in the resulting stream -- e.g.:
and you fix script.pl so that it knows to look for the specific string that flags the stream boundary.)echo "____STREAM_BOUNDARY____" > bndry grep "target string" file1 | cat - bndry file2 | script.pl
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: what is EOF and how can I send it?
by revdiablo (Prior) on Jun 06, 2004 at 15:45 UTC |