Here are some notes to help you understand get_line:
!defined($buf) is only true the first time get_line is called. It proceeds to trash all the lines before the first timestamped line, if any.
The file is processed as follows:
File Read by Returned by ----------------- ----------- ----------- line 1st call(*) scrapped line 1st call(*) scrapped timestamped line 1st call(*) 1st call line 1st call 1st call line 1st call 1st call timestamped line 1st call 2nd call line 2nd call 2nd call line 2nd call 2nd call timestamped line 2nd call 3rd call line 3rd call 3rd call line 3rd call 3rd call timestamped line 3rd call 4th call EOF 4th call 5th call
* — By the body of if (!defined($buf)).
Between calls, $buf contains the line that has been read, but not returned.
our $var; local *var = \($self->[$idx]);
creates an alias so that any change to $var is reflected in $self->[$idx].
for (;;) can be read as "for ever". The loop will loop until last, return, die, exit or other exceptional means are used to exit it.
return ((undef, $buf) = ($buf, $line))[0];
is short for
my $temp = $buf;
$buf = $line;
return $temp;
In reply to Re^3: text parsing question
by ikegami
in thread text parsing question
by perlAffen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |