learingperl01
MIS
Hello I have the following code in my script that does not seem to work and I can figure out why it's not working. Hoping that someone could please help me out.
open(HAN2, "/home/testuser01/test.txt") || die "Count not open test.txt file";
while (<HAN2>) {
@array1=[ split ];
foreach (@array1) {
print @$_, "\n"; # Testing purposes
if (@$_ =~ /^\s+$/) {
print "found", "@$_", "\n";
}
}
}
The file test.txt contains
blank/null line
aaaaaa
bbbbbb
cccccc
So when I print I would like it to only print what is shown below and not the blank line.
aaaaa
bbbbb
ccccc
But it prints
null/blank line along with
aaaaa
bbbbb
ccccc
In reality what I am trying to do is not print any lines in the array which it reads from a file, which are blank. I have a file which sometimes has blank lines but don't want those to be printed. I am sure there is an easier way to do this and I would love to learn them, but I would also love to know what I am doing wrong/why the print is printing the blank line along with the lines which contain data.
thanks for the help in advance.
open(HAN2, "/home/testuser01/test.txt") || die "Count not open test.txt file";
while (<HAN2>) {
@array1=[ split ];
foreach (@array1) {
print @$_, "\n"; # Testing purposes
if (@$_ =~ /^\s+$/) {
print "found", "@$_", "\n";
}
}
}
The file test.txt contains
blank/null line
aaaaaa
bbbbbb
cccccc
So when I print I would like it to only print what is shown below and not the blank line.
aaaaa
bbbbb
ccccc
But it prints
null/blank line along with
aaaaa
bbbbb
ccccc
In reality what I am trying to do is not print any lines in the array which it reads from a file, which are blank. I have a file which sometimes has blank lines but don't want those to be printed. I am sure there is an easier way to do this and I would love to learn them, but I would also love to know what I am doing wrong/why the print is printing the blank line along with the lines which contain data.
thanks for the help in advance.