http://www.perlmonks.org?node_id=180287


in reply to Re: Simple file to array
in thread Simple file to array

Sure, this could use some explaining. But not too much. :)

When using a filehandle in list context (such as assigning it to an array), each line is treated as a list element and assigned to the array just like if you were doing my @email_addys = ('x@y.com', 'foo@bar.org', ... ).

One of the problems here is that this doesn't strip the linefeed character from the end of each line, so that what we end up with is an array like ("x@y.com\n", "foo@bar.org\n") when reading this from a file. We probably want to clean up the array, which we can do quickly with for( @email_addys ){ chomp }; at some point after the assignment.