You have a serious something that could be
a misconception here:
@list = <>;
...
$number = <>; <strike># this will never be reached (or won't read any
+thing)</strike>
When you assign lines of input to "@list", this tells perl
to read until the "end of file", which in the case of stdin
means "until user hits '^D' (on a unix system) or '^Z' (on
a windows/dos system)"; then of course, having terminated
the input to the script on stdin, perl cannot read anything
more. if the user doesn't know the proper etiquette
for terminating manual input on stdin, this script will seem
uncooperative. (Thanks to sauoq for reminding me about how
perl really handles the <> input operator and
end-of-file signals in that context.)
It would be better -- both for the program logic, and for
the user, too, I think -- to structure the program so that
it reads the list from some file; the user may provide the
file name as a command line argument, or, if you insist, he
can enter the file name in response to a prompt from the
script. In either case, the script gets the file name in
a scalar variable, you open that file, and read its
contents into @list; e.g.:
open(LIST, "<$ARGV[0]");
@list = <LIST>;
close LIST;
Then you prompt the user for a line number, and do what you
want with that information. (Might be helpful, when prompting
for that, to indicate how many lines are available to choose
from.)
print "Pick a number between 1 and ",scalar @list,": ";
$line_no = <STDIN>;
chomp $line_no;
print "Contents of line # $line_no in $ARGV[0]:\n$list[$line_no-1]\n";
|