On Sun, Mar 29, 2009 at 22:20, John W. Krahn <jwkr...@shaw.ca> wrote:
> Kelly Jones wrote:
>>>
>>> perl -le '$x=<STDIN>; print $x'
>>
>> hello <- I TYPED THIS IN AND HIT RETURN
>> hello
>>
>>> perl -le 'my($x)=<STDIN>; print $x'
>>
>> hello <- I TYPED THIS IN AND HIT RETURN
>> [no answer, hangs forever]
>
> $x=<STDIN> is in scalar context so only one line is read.
>
> ($x)=<STDIN> is in list context so readline keeps reading util the
> end-of-file is reached.  To signal end-of-file in Unix/Linux type Ctrl-D or
> in DOS/Windows type Ctrl-Z.
snip

It is important to note that you will only get the first line[1] of
the input this way.  This is because $x can only hold on of the items
returned by <>.  In list context items are assigned in order, so in

    my ($first, $second, $third) = <>;

The first line will be assigned to $first, the second line will be
assigned $second, and so on.

1. depending on what $/ is at the time, it may not be one line.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to