You have good answers that address your immediate problems. However it looks like you are starting out on your Perl journy. May I suggest that you spend a little time perusing the Tutorials section here and especially Getting Started with Perl, Getting Deeper Into Perl and Pattern Matching, Regular Expressions, and Parsing (which is one of the reasons for choosing Perl after all).

Although I've never programmed Lisp, @arr1 = (@arr1,$_); has a Lispish flavour to it. In Perl it is more conventional to use push (as shown in some of the other answers) to add elements to the end of an array, or unshift to add elements to the start of an array. In similar fashion pop and shift are used to remove the element from the end and start of an array respectively.

Other list processing functions that are well worth being aware of are join, map and grep. For example the print loop could be rewritten using join as:

print join "\n", @arr1, '';

Note, the , '' on the end ensures a newline is emitted following the last array element.


DWIM is Perl's answer to Gödel

In reply to Re: Input to array from STDIN, then print, but print is not working by GrandFather
in thread Input to array from STDIN, then print, but print is not working by Anonymous Monk

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.