I
IanW
I'm looping through each line of a text file, with a format like this:
# start of file
===============
Line 1
Line 2
Line 3
===============
Line 1
Line 2
Line 3
===============
Line 1
Line 2
Line 3
# end of file
I am processing it in chunks where "===============" is the start of each
chunk.
So after opening the file (FH), I while-loop through it like this:
my @chunk = ();
while(my $ln = <FH>){
if(($ln =~ /^={15}$/ or eof) and scalar @chunk > 0){
# process @chunk
undef @chunk;
}
push(@chunk,$ln);
}
That works nicely except that when it gets to the end of the file "Line 3"
above is not added to @chunk. I would have expected eof to test positive
when it gets to the end of the blank line. Am I missing something obvious
here or is there a quirk with the usage of eof?
IanW
# start of file
===============
Line 1
Line 2
Line 3
===============
Line 1
Line 2
Line 3
===============
Line 1
Line 2
Line 3
# end of file
I am processing it in chunks where "===============" is the start of each
chunk.
So after opening the file (FH), I while-loop through it like this:
my @chunk = ();
while(my $ln = <FH>){
if(($ln =~ /^={15}$/ or eof) and scalar @chunk > 0){
# process @chunk
undef @chunk;
}
push(@chunk,$ln);
}
That works nicely except that when it gets to the end of the file "Line 3"
above is not added to @chunk. I would have expected eof to test positive
when it gets to the end of the blank line. Am I missing something obvious
here or is there a quirk with the usage of eof?
IanW