http://www.perlmonks.org?node_id=1024840


in reply to Limited Number of User Input

EDIT: found out how to do this, using

while (my $text = <STDIN>) { chomp($text); print "You entered '$text'\n"; last if ($text eq ''); }

but with a counter instead of "last"

Replies are listed 'Best First'.
Re^2: Limited Number of User Input
by rjt (Curate) on Mar 22, 2013 at 00:22 UTC

    Yes, good. May I ask, why do you ask the user to enter the number of files first when you already know the simple, intuitive (and very commonly used) way like this for the user to indicate they're finished? If you need to know how many files they entered, you can do something like this:

    while (<STDIN>) { chomp; last if $_ eq ''; push @files, $_; } printf "You entered %d files: { %s }\n", scalar @files, join(' ', @fil +es);