I'm going insane, right? Trying to trim newlines out of an array read from a file. I'm a relative newb, but everything I've read on the internet tells me this should work. (I've taken out all the format validation for testing).

input.txt has this in it:

111.111.111.111 222.222.222.222 333.333.333.333
Here is my snippet:
my $File = input.txt; open(FILE, "$File"); @IPLIST = <FILE>; close(FILE); foreach my $test (@IPLIST) { print "Is $test an IP?\n"; }
Output looks like this:
Is 111.111.111.111 an IP? Is 222.222.222.222 an IP? Is 222.222.222.222 an IP?
Expected behavior, right? So then I add chomp(@IPLIST); before my loop, and the output becomes this:
Is an IP? Is an IP? Is an IP?
Same behavior if I do it on the read:  chomp( @IPLIST = <FILE> ); or in the loop for each element. Isn't chomp supposed to do the opposite of this??? What am I missing?


In reply to chomp removes everything *except* the newline? by follier

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.