Try this:
use strict; use warnings; print "Enter five numbers (hit ctrl-d to terminate final input):\n"; my @array; while( <> ){ last if $. > 4; chomp; push @array, $_; } print "$_\n" foreach @array;
This uses special variable $. to automatically count the input line for you. This eliminates the need for "$i <= 4". You could replace "last if $. > 4;" with "last if $i++ > 4;" to similar effect.
Dave
In reply to Re: Input to array from STDIN, then print, but print is not working
by davido
in thread Input to array from STDIN, then print, but print is not working
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |