Perl: avoid greedy reading from stdin?
问题 Consider the following perl script ( read.pl ): my $line = <STDIN>; print "Perl read: $line"; print "And here's what cat gets: ", `cat -`; If this script is executed from the command line, it will get the first line of input, while cat gets everything else until the end of input ( ^D is pressed). However, things are different when the input is piped from another process or read from a file: $ echo "foo\nbar" | ./read.pl Perl read: foo And here's what cat gets: Perl seems to greadily buffer