Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

(ichi) re x 2: Simple file to array

by ichimunki (Priest)
on Jul 08, 2002 at 19:32 UTC ( #180287=note: print w/ replies, xml ) Need Help??


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.


Comment on (ichi) re x 2: Simple file to array
Select or Download Code
Re: (ichi) re x 2: Simple file to array
by fruiture (Curate) on Jul 08, 2002 at 19:42 UTC
    We probably want to clean up the array, which we can do quickly with for( @email_addys ){ chomp }; at some point after the assignment.

    `perldoc -f chomp` tells us an easier way: chomp @email_addys.

      Yes, that is much nicer, isn't it? :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://180287]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (16)
As of 2014-10-20 18:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (87 votes), past polls