[comp.lang.perl] why doesn't my usage of "while

al@ee.pitt.edu (Alan Martello) (11/17/90)

what is wrong with this example ?  I want to rsh to another
machine, process the output of the command, and then
use "while(<>)" just like always.  

any help appreciated, please post (unless embarassing) or mail.
I'm running perl PL 41 on a Sun-3 under SunOS 4.1
compiled with gcc.

*******************************************************************
       Alan R. Martello        Electrical Engineering Dept.
        al@ee.pitt.edu           University of Pittsburgh
*******************************************************************
#! /bin/perl

#  get the host name for the rsh
$host = $ENV{'HOST'};

#
#  THESE NEXT THREE LINES ARE THE OFFENDING ONES
#  why does this program work only when these are
#  commented out ?
open(WFH, "rsh $host ls |");
while (<WFH>) {  print; }
close(WFH);

#
#  second while statement should copy stdin to stdout
#
while (<>) {
  print;
}
exit;

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (11/17/90)

In article <9231@pitt.UUCP> al@ee.pitt.edu (Alan Martello) writes:
: what is wrong with this example ?  I want to rsh to another
: machine, process the output of the command, and then
: use "while(<>)" just like always.  
: 
: any help appreciated, please post (unless embarassing) or mail.
: I'm running perl PL 41 on a Sun-3 under SunOS 4.1
: compiled with gcc.
: 
: *******************************************************************
:        Alan R. Martello        Electrical Engineering Dept.
:         al@ee.pitt.edu           University of Pittsburgh
: *******************************************************************
: #! /bin/perl
: 
: #  get the host name for the rsh
: $host = $ENV{'HOST'};
: 
: #
: #  THESE NEXT THREE LINES ARE THE OFFENDING ONES
: #  why does this program work only when these are
: #  commented out ?
: open(WFH, "rsh $host ls |");
: while (<WFH>) {  print; }
: close(WFH);
: 
: #
: #  second while statement should copy stdin to stdout
: #
: while (<>) {
:   print;
: }
: exit;

Works fine for me.  Could you have something weird in your .cshrc that's
trying to do dialog and getting nothing from stdin?  Try

    open(WFH, "rsh $host ls </dev/null 2>&1 |");

Larry