manish.rathi has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: <input> for array
by ikegami (Patriarch) on Feb 17, 2009 at 16:20 UTC

    <> in list context (as it is in @_ = <STDIN>) reads until the end of the file (which ^Z signals).

    But you have that in a loop, so it keeps reading to the end of the file over and over again until the while loop exits. That will happen when zero lines are returned by <STDIN>.

    Please use <p> at the start of every paragraph and <c>...</c> around your code. You should know this by now.

Re: <input> for array
by kennethk (Abbot) on Feb 17, 2009 at 16:20 UTC

    First, <code> tags are your friends - please read Writeup Formatting Tips.

    This issue you are encountering is a question of scalar context for an array. Your first code tests $_ to see if it is false and exits the loop if it is. When you enter your control character, that evaluates to false and the while loop exits. You second code checks @_. Since this is an array, in scalar context (such as a conditional), it evaluates to the number of elements contained therein. Since it contains 1 element, it is true and thus the loop will not break. Read perldata for more details.

Re: <input> for array
by targetsmart (Curate) on Feb 17, 2009 at 16:21 UTC
    <> behaves differently according to the context, in scalar context it fetches a single line, in list context it fetches lines until end of file(EOF).

    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
Re: <input> for array
by lakshmananindia (Chaplain) on Feb 18, 2009 at 04:37 UTC