Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

(ichi) re x 2: Simple file to array

by ichimunki (Priest)
on Jul 08, 2002 at 19:32 UTC ( [id://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.

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://180287]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-16 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found