Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!pitt!io!al From: al@ee.pitt.edu (Alan Martello) Newsgroups: comp.lang.perl Subject: ANSWER Re: why doesn't my usage of "while(<>)" work ? Message-ID: <9243@pitt.UUCP> Date: 19 Nov 90 20:49:06 GMT References: <9231@pitt.UUCP> <10437@jpl-devvax.JPL.NASA.GOV> Sender: news@pitt.UUCP Reply-To: al@ee.pitt.edu (Alan Martello) Organization: Electrical Engineering, Univ. of Pittsburgh Lines: 54 In article <10437@jpl-devvax.JPL.NASA.GOV>, lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: |> 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. |> : |> : #! /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 () { 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 &1 |"); |> |> Larry Thanks Larry, right guess again! the problem was an interaction (probably in .login querying for a terminal or some such). Anyway, either both of these open statements fixes it (the second one may only be valid on my Sun). open(WFH, "rsh $host ls &1 |"); open(WFH, "rsh $host -n ls |"); I haven't decided if this was a subtle mistake or a stupid one... ******************************************************************* Alan R. Martello Electrical Engineering Dept. al@ee.pitt.edu University of Pittsburgh *******************************************************************