follier has asked for the wisdom of the Perl Monks concerning the following question:
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:
Here is my snippet:111.111.111.111 222.222.222.222 333.333.333.333
Output looks like this:my $File = input.txt; open(FILE, "$File"); @IPLIST = <FILE>; close(FILE); foreach my $test (@IPLIST) { print "Is $test an IP?\n"; }
Expected behavior, right? So then I add chomp(@IPLIST); before my loop, and the output becomes this:Is 111.111.111.111 an IP? Is 222.222.222.222 an IP? Is 222.222.222.222 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?Is an IP? Is an IP? Is an IP?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: chomp removes everything *except* the newline?
by Anonymous Monk on Jun 26, 2010 at 17:33 UTC | |
by follier (Initiate) on Jun 26, 2010 at 18:41 UTC | |
by almut (Canon) on Jun 26, 2010 at 18:56 UTC | |
by GrandFather (Saint) on Jun 26, 2010 at 21:50 UTC | |
|
Re: chomp removes everything *except* the newline?
by Anonymous Monk on Jun 26, 2010 at 17:29 UTC | |
|
Re: chomp removes everything *except* the newline?
by ikegami (Patriarch) on Jun 27, 2010 at 07:37 UTC |