Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by mldvx4 (Pilgrim)
on May 01, 2017 at 12:29 UTC ( #1189255=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1189255]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2022-05-21 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (76 votes). Check out past polls.

    Notices?