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

Dear Monks,

I'm new to Perl, so my question might seem stupid, but please don't laugh.

I want to write a program to capture all incomes to be enterred by the user. I can print a question, and prompt for user to enter their different incomes and capture these with the use of an array as per below:

print "Enter incomes: /n"; @income=<STDIN>;
My problem is, how can I put a stop to the array without prompting for user to press Ctl+D to enter an EOF?

Your help is much appreciated!

Thanks & regards,
PerlNovice

update (broquaint): added formatting + <code> tags

Replies are listed 'Best First'.
Re: Array input
by diotalevi (Canon) on Nov 14, 2002 at 03:39 UTC

    This is easy - do something like while($line = <STDIN>) { chomp $line; last unless $line =~ /\d/; push @income, $line }. The idea is you read data until something "different" happens. My example terminates when the user enters a line without any numbers in it. You should pick something more appropriate to your own use.

    __SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;
      THANK YOU DIOTALEVI! You're very prompt with your reply, so prompt that I'm impressed. I've searched many PERL sites, and must admit, this one is a wealth of knowledge!!! I'm destined to be a regular visitor at Perlmonks.org now. Once again, thanks!

        Well good. Now go get yourself a real user account over here at Creating an account on PerlMonks and join us.

        __SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;