Jul 6, 2010, 10:34 PM
Post #1 of 2
using text file lines to create a list
I am trying to take the lines of a text file and turn them into an array variable.
My text file is called log.txt and is a simple text file with the following lines:
I would like to take each of these lines and place them into an array variable called @array_variable, so that each element corresponds to a line of the text file. As in $array_variable="line_1" and so on.
So I tried to the following code:
open (MYINPUTFILE, "<log.txt");
my $line = $_;
However I can only get the variable $line to equal the corresponding line of the text file within the while loop. However when I call it from outside the while loop, Perl complains that $line requires an explicit package name.
Does anyone know how I can take the contents of a text file, line-by-line, and convert them into an array variable for Perl.