in reply to Re: Simple file to array
in thread Simple file to array
This line opens the file "addys.txt" to filehandle FH. The function open will return a true value if the file open's sucessfully and a false value if it fails. If the file opens sucessfully the or will "short circuit" meaning since it already has a true value there is no need to evaluate the rest of the statement. If the open fails the die will be executed and the program will quit giving an error message. This is a pretty common way of testing that an open succeeded. You should always check the return value of an open it will usually save you a lot of debug time.open( FH, 'addys.txt' ) or die "Couldn't open file: $!" ;
This line does the bulk of what you ask for. The my @email_addys creates a lexical array variable to hold the email addresses. The diamond operator ( <> ) on a filehandle reads the next line from the file. If it is being used in what is called a list context it will slurp up the whole file and return a list where each line of the file will be one of the elements of the list.my @email_addys = <FH> ;
Close the filehandle.close( FH ) ;
Notes: Each element of the @email_addys array will have a trailing newline "\n" (except maybe the last one depending on whether the last line of the file had a newline at the end.)
--
flounder
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Simple file to array
by Foncé (Scribe) on Jul 09, 2002 at 12:30 UTC |