try scalar(<STDIN>) On Wed, Dec 15, 2010 at 3:05 PM, Assaf Gordon <gor...@cshl.edu> wrote:
> Hello all, > > Perhaps you could help me with some perl weirdness (or my lack of > understanding)... > > My goal is to have a tiny perl program, that reads STDIN, grabs couple of > lines from it, then executes another program which should consume the rest > of the lines from STDIN. > > This works as expected when using shell redirection, but not when using > pipes. > > I've tried it on two different systems (Debian with perl 5.10.1 and CentOS > with perl 5.8.8). > > Complete details below. > Any suggestions will be very welcomed. > > Thanks, > -Assaf > > ======= > > $ cat input.txt > A > B > C > D > > ### The first program does nothing but run "sort" > $ cat test_good.pl > #!/usr/bin/perl > system("sort"); > > ### Redirection works > $ ./test_good.pl < input.txt > A > B > C > D > > ### Pipes work > $ cat input.txt | ./test_good.pl > A > B > C > D > > > ### The second program reads one line from STDIN, then runs "sort" > $ cat test_bad.pl > #!/usr/bin/perl > $dummy = <STDIN>; > system("sort"); > > ### Redirection still works (first line removed) > $ ./test_bad.pl < input.txt > B > C > D > > ### Pipes do not work - why ??? > $ cat input.txt | ./test_bad.pl > ## nothing is printed > > ================== > > _______________________________________________ > Perl mailing list > Perl@perl.org.il > http://mail.perl.org.il/mailman/listinfo/perl > -- Tzadik
_______________________________________________ Perl mailing list Perl@perl.org.il http://mail.perl.org.il/mailman/listinfo/perl