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";

In reply to Re: printing array and string on same line by graff
in thread printing array and string on same line by BigRare

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.