Hello harangzsolt33,

Angle brackets around a filehandle are a special Perl construct for calling the built-in readline function, which (like most Perl functions) behaves differently according to the context in which it appears. From the documentation:

In scalar context, each call reads and returns the next line until end-of-file is reached, whereupon the subsequent call returns undef. In list context, reads until end-of-file is reached and returns a list of lines.

The line my $L = <STDIN>; supplies a scalar context, and so only one line is read since readline is called only once.

By contrast, the line print <STDIN>; supplies a list context (see print), so multiple lines may be read in by a single call.

Change your second example as follows: my @L = <STDIN>; print @L; and you will see the same behaviour as in the first example. On Windows (where ^Z signals end-of-file):

12:31 >perl -wE "my @L = <STDIN>; print @L;" abc def ghi ^Z abc def ghi 12:31 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Printing from stdin to stdout by Athanasius
in thread Printing from stdin to stdout by harangzsolt33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.