Here is another one of these weird things. I have this code and a file.
use strict;
use warnings;
my $file = "test.txt";
my @arr;
open (LOGFILE, $file);
while (my $line = <LOGFILE>)
{
#print $line;
@arr = split("\n", $line);
}
close LOGFILE;
print $arr[1];
test.txt contains
\ntest1 \ntest2 \ntest3
Here is the error I get:
Use of uninitialized value in print at test.pl line 15.
Did anyone encounter a similar problem in the past?
split
takes a regex (I believe your string is coerced into a regex). Maybe something like split(/\\n/, $line)
?
use strict;
use warnings;
my $file = "test.txt";
my @arr;
open (LOGFILE, $file);
while (my $line = <LOGFILE>)
{
print $line;
@arr = split(/\\n/, $line);
}
close LOGFILE;
print $arr[1];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With