Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone, Newbie working my way through "Learning Perl" by Schwartz. I seem to be having problems with populating a list with <STDIN> from the keyboard. Here's the sample code:
#!perl #use warnings; use 5.010; chomp(@array = <STDIN>); print "It worked!!";
The book says if I press control+b (unix) or control+z (windows, which I'm using), that this should end the keyboard entry and move on to the next line of code. But it doesn't, no matter how many times I press ctrl+z ... or any other combination for that fact. Please help!!!

Replies are listed 'Best First'.
Re: newbie and <STDIN>
by ikegami (Patriarch) on Jan 10, 2009 at 05:19 UTC

    On a blank line (i.e. before typing anything else or after pressing Enter), press Ctrl-Z followed by Enter.

    In unix, it's usually Ctrl-D rather than Ctrl-B, but it's configurable. It also has to be on blank line.

Re: newbie and <STDIN>
by syphilis (Archbishop) on Jan 10, 2009 at 05:04 UTC
    Ctrl-Z, then hit "Enter". (Works for me, at least.)

    Cheers,
    Rob
Re: newbie and <STDIN>
by davido (Cardinal) on Jan 10, 2009 at 06:35 UTC
    chomp( @array = <STDIN> ); print "It worked!!";

    I love that approach to error-checking. If only it were that easy all of the time!. ;)


    Dave

Re: newbie and <STDIN>
by neutron (Sexton) on Jan 10, 2009 at 14:14 UTC
    Hi everyone, back again, but this time with a login, woohoo.

    Anyway, thanks for the pointers. I've been using Perl Builder 2.0 and have been struggling with user inputs in general, not just lists. I'm using strawberry now and everything seems to be working great! Will take a little time getting used to dos interface, but at least it works.