prasaduco has asked for the wisdom of the Perl Monks concerning the following question:

#!/usr/bin/perl use strict; use warnings; my($line) = <STDIN>; if ($line ne 0) { print "You just wrote $line\n"; }

Hi I just wanted to read one line of input. I am using Perl 5.8.6 on Unix Darwin for max os tiger. However, as soon as i type one line "my name is xyz" and hit enter it does nothing but go the next blank line. I need to print the entire line entered, till i hit enter.

Replies are listed 'Best First'.
Re: How do I read just one line of input
by moritz (Cardinal) on Jul 15, 2011 at 14:31 UTC
    my ($line) = ... puts the right-hand side into list context. In list context, the <> operator reads all lines in the file/stream.

    In scalar context, only the first line is read, so change that to

    my $line = <STDIN>;

      Thanks Moritz, it worked :)