Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!umich!samsung!sdd.hp.com!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: STDIN waits for ^D, not newline Message-ID: <1990May9.223157.12674@iwarp.intel.com> Date: 9 May 90 22:31:57 GMT References: <5249@crltrx.crl.dec.com> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 52 In-Reply-To: halbert@halbert.crl.dec.com (Dan Halbert) In article <5249@crltrx.crl.dec.com>, halbert@halbert (Dan Halbert) writes: | (Using Perl version: | $Header: perly.c, v 3.0.1.4 90/02/28 18:06:41 lwall Locked $ | Patch level: 15) | | I'm writing an interactive terminal program in perl. It prompts the user | and reads from STDIN. | | If you try this program: | | print "prompt: "; | $a = ; | print $a; | | then a carriage return will end the input. (That is, will read | one line.) | | However, if you try: | | print "prompt: "; | local ($a) = ; | print $a; | | then STDIN keeps reading input until I type ^D. | | In my program, the local() is in a subroutine, of course, but that isn't | necessary to reproduce the problem. | | Opening "-" explicitly doesn't solve the problem. | | I just started looking at comp.lang.perl; sorry if this is old hat. Not old hat. I don't recall seeing this one before. But, the problem (without testing it) is that local($a) = ; is an _array assignment_. So, , being very helpful, is sucking all of standard input into an array, and then giving the first line into $a, while discarding the rest. This works better (but looks ugly -- Larry?): local($a) = "".; Which basically says to interpret in a scalar context (a string concatenation), and pass the result to the assignment. $|=1;$_=",rekcah lreP rehtona tsuJ";while(length){exit wait if fork;s/.$//;print$&;} -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/