Prev: How to generate random number without replacement?
Next: FAQ 4.76 How do I verify a credit card checksum?
From: Peng Yu on 31 May 2010 23:47 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 1 Jun 2010 00:12 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 1 Jun 2010 04:24 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 1 Jun 2010 05:16 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 1 Jun 2010 05:26 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 "------\n"; while(<IN2>) { } $ ./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 "------\n"; while(<IN2>) { } ------ #!/usr/bin/env perl use warnings; open(IN1, $ARGV[0]); open(IN2, $ARGV[1]); while(<IN1>) { } print "------\n"; while(<IN2>) { }
|
Next
|
Last
Pages: 1 2 3 Prev: How to generate random number without replacement? Next: FAQ 4.76 How do I verify a credit card checksum? |