1#!./perl 2 3# test added 29th April 1999 by Paul Johnson (pjcj@transeda.com) 4# updated 28th May 1999 by Paul Johnson 5 6my $File; 7 8BEGIN { 9 $File = __FILE__; 10 require strict; import strict; 11} 12 13use Test; 14 15BEGIN { plan tests => 12 } 16 17use IO::File; 18 19sub lineno 20{ 21 my ($f) = @_; 22 my $l; 23 $l .= "$. "; 24 $l .= $f->input_line_number; 25 $l .= " $."; # check $. before and after input_line_number 26 $l; 27} 28 29my $t; 30 31open (F, $File) or die $!; 32my $io = IO::File->new($File) or die $!; 33 34<F> for (1 .. 10); 35ok(lineno($io), "10 0 10"); 36 37$io->getline for (1 .. 5); 38ok(lineno($io), "5 5 5"); 39 40<F>; 41ok(lineno($io), "11 5 11"); 42 43$io->getline; 44ok(lineno($io), "6 6 6"); 45 46$t = tell F; # tell F; provokes a warning 47ok(lineno($io), "11 6 11"); 48 49<F>; 50ok(lineno($io), "12 6 12"); 51 52select F; 53ok(lineno($io), "12 6 12"); 54 55<F> for (1 .. 10); 56ok(lineno($io), "22 6 22"); 57 58$io->getline for (1 .. 5); 59ok(lineno($io), "11 11 11"); 60 61$t = tell F; 62# We used to have problems here before local $. worked. 63# input_line_number() used to use select and tell. When we did the 64# same, that mechanism broke. It should work now. 65ok(lineno($io), "22 11 22"); 66 67{ 68 local $.; 69 $io->getline for (1 .. 5); 70 ok(lineno($io), "16 16 16"); 71} 72 73ok(lineno($io), "22 16 22"); 74