From: Peng Yu on
diff can take two input streams in the following example (if my
interpretation is correct).

diff <(gunzip <a.gz) <(gunzip b.gz)

I'm wondering how to take two streams in a perl program.
From: Alan Curry on
In article <d31764b8-cd92-47d0-a0af-39292fede94d(a)f13g2000vbm.googlegroups.com>,
Peng Yu <pengyu.ut(a)gmail.com> wrote:
>diff can take two input streams in the following example (if my
>interpretation is correct).

diff *requires* two input streams. With only one, it's hard to figure what it
would do.

>
>diff <(gunzip <a.gz) <(gunzip b.gz)
>
>I'm wondering how to take two streams in a perl program.

The <(cmd) syntax is handled by your shell, which substitutes a filename
which may be opened to gain access to the stream. diff doesn't know anything
abou it. diff just finds 2 filenames in argv, opens them, and reads them. You
can do the same in any language, including perl.

--
Alan Curry
From: Martijn Lievaart on
On Mon, 31 May 2010 20:47:22 -0700, Peng Yu wrote:

> diff can take two input streams in the following example (if my
> interpretation is correct).
>
> diff <(gunzip <a.gz) <(gunzip b.gz)
>
> I'm wondering how to take two streams in a perl program.

This has nothing to do with diff or with perl, it's a function of your
shell. So it works the same for diff as for perl.

HTH,
M4
From: Peng Yu on
On Jun 1, 3:24 am, Martijn Lievaart <m...(a)rtij.nl.invlalid> wrote:
> On Mon, 31 May 2010 20:47:22 -0700, Peng Yu wrote:
> > diff can take two input streams in the following example (if my
> > interpretation is correct).
>
> > diff <(gunzip <a.gz) <(gunzip b.gz)
>
> > I'm wondering how to take two streams in a perl program.
>
> This has nothing to do with diff or with perl, it's a function of your
> shell. So it works the same for diff as for perl.

I don't quite understand how this works. Would you please write a
small perl program which can print the two streams (with the following
command) to help me understand it?

example.pl <(cat a.txt) <(cat b.txt)
From: Peng Yu on
On Jun 1, 3:24 am, Martijn Lievaart <m...(a)rtij.nl.invlalid> wrote:
> On Mon, 31 May 2010 20:47:22 -0700, Peng Yu wrote:
> > diff can take two input streams in the following example (if my
> > interpretation is correct).
>
> > diff <(gunzip <a.gz) <(gunzip b.gz)
>
> > I'm wondering how to take two streams in a perl program.
>
> This has nothing to do with diff or with perl, it's a function of your
> shell. So it works the same for diff as for perl.

I think that I understand what you mean. <(cmd) is just like a
filename, right?

$ cat main.pl
#!/usr/bin/env perl

use warnings;

open(IN1, $ARGV[0]);
open(IN2, $ARGV[1]);

while(<IN1>) {
print
}

print "------\n";

while(<IN2>) {
print
}

$ ./main.pl <(cat main.pl) <(cat main.pl)
#!/usr/bin/env perl

use warnings;

open(IN1, $ARGV[0]);
open(IN2, $ARGV[1]);

while(<IN1>) {
print
}

print "------\n";

while(<IN2>) {
print
}

------
#!/usr/bin/env perl

use warnings;

open(IN1, $ARGV[0]);
open(IN2, $ARGV[1]);

while(<IN1>) {
print
}

print "------\n";

while(<IN2>) {
print
}