Hi,
I´m preparing a perl script that reads a file and then treats it line by line.
The line
print "$_\n";
prints correctly the 4 lines the file it is reading has.
However, the line
print "@lines\n";
prints an output of:
Line1
Line1Line2
Line1Line2Line3
Line1Line2Line3Line4
(a section of the script is included below)
So this shows that "pushing" $_ onto the array @lines as long as there is a new line to read in the file (4 lines in my example) is concatenating the new value to the previous one. How can I do the same thing without concatenating it? I just want the array to contain what is in the file so i can treat the contents line by line.
Thanks in advance,
T.
=====================================================
open (FILE, "< $filename") or die "Cant open $filename: $!";
while (<FILE>)
{
s/"*"//; #ignore comments and ORA_HOME with no db defined
next if /^(\s)*$/; #skip blank lines
chomp; #remove trailing newline
print "$_\n";
push (@lines, $_); #push the data line onto the array
print "@lines\n";
}
close FILE;
I´m preparing a perl script that reads a file and then treats it line by line.
The line
print "$_\n";
prints correctly the 4 lines the file it is reading has.
However, the line
print "@lines\n";
prints an output of:
Line1
Line1Line2
Line1Line2Line3
Line1Line2Line3Line4
(a section of the script is included below)
So this shows that "pushing" $_ onto the array @lines as long as there is a new line to read in the file (4 lines in my example) is concatenating the new value to the previous one. How can I do the same thing without concatenating it? I just want the array to contain what is in the file so i can treat the contents line by line.
Thanks in advance,
T.
=====================================================
open (FILE, "< $filename") or die "Cant open $filename: $!";
while (<FILE>)
{
s/"*"//; #ignore comments and ORA_HOME with no db defined
next if /^(\s)*$/; #skip blank lines
chomp; #remove trailing newline
print "$_\n";
push (@lines, $_); #push the data line onto the array
print "@lines\n";
}
close FILE;