$. is error prone, as one can have multiple files open in a program, but there is only one $. I would rather call input_line_number() with specific file handler.
use IO::Handle;
open(MYSELF1, "<", "test.pl");
open(MYSELF2, "<", "test.pl");
while (<MYSELF1>) {
print "after reading from myself1: $.\n";
if ($. % 2) {
<MYSELF2>;
print "after reading from myself2: $.\n";
}
print "returned values from input_line_number: (";
print MYSELF1->input_line_number(), ", ";
print MYSELF2->input_line_number(), ")\n";
}
close(MYSELF1);
close(MYSELF2);
|