in reply to Re: perl -n seemingly eating a line of input
in thread perl -n seemingly eating a line of input

Thanks. I see the problem now, though don't see the way around it. Adding the parenthesis catches the first number, but also produces an extra line that is empty.

  • Comment on Re^2: perl -n seemingly eating a line of input

Replies are listed 'Best First'.
Re^3: perl -n seemingly eating a line of input
by shmem (Chancellor) on May 01, 2017 at 13:18 UTC
    ...but also produces an extra line that is empty.

    That is due to your trailing \n and has nothing to do with the parenthesized $_,<> - compare

    echo -e '55\n44\n33\n22\n11\n' | perl -n -e '@a = ($_,<>); END{ print +@a; } ' echo -e '55\n44\n33\n22\n11' | perl -n -e '@a = ($_,<>); END{ print @a +; } '

    - because echo -e will add a newline to its argument, so there are two of them, and thus an empty line. Use echo -en to suppress that:

    echo -en '55\n44\n33\n22\n11\n' | perl -n -e '@a = ($_,<>); END{ print + @a; } '
    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^3: perl -n seemingly eating a line of input
by bart (Canon) on May 01, 2017 at 13:00 UTC
    Don't use -n, or change the way you process the lines:
    echo -e '55\n44\n33\n22\n11\n' | perl -n -e 'push @a, $_; END{ print @ +a; } '

    Explanation: -n makes perl loop through the input lines, and my code puts each line in turn onto the array. After all input is processed, I print out the array.

Re^3: perl -n seemingly eating a line of input
by Anonymous Monk on May 01, 2017 at 12:46 UTC
    If you want to do -e '@a=<>;' and get all the lines, simply don't use -n.