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; strict->import(); 11} 12 13use Test::More tests => 12; 14 15use IO::File; 16 17sub lineno 18{ 19 my ($f) = @_; 20 my $l; 21 $l .= "$. "; 22 $l .= $f->input_line_number; 23 $l .= " $."; # check $. before and after input_line_number 24 $l; 25} 26 27my $t; 28 29open (F, '<', $File) or die $!; 30my $io = IO::File->new($File) or die $!; 31 32<F> for (1 .. 10); 33is(lineno($io), "10 0 10"); 34 35$io->getline for (1 .. 5); 36is(lineno($io), "5 5 5"); 37 38<F>; 39is(lineno($io), "11 5 11"); 40 41$io->getline; 42is(lineno($io), "6 6 6"); 43 44$t = tell F; # tell F; provokes a warning 45is(lineno($io), "11 6 11"); 46 47<F>; 48is(lineno($io), "12 6 12"); 49 50select F; 51is(lineno($io), "12 6 12"); 52 53<F> for (1 .. 10); 54is(lineno($io), "22 6 22"); 55 56$io->getline for (1 .. 5); 57is(lineno($io), "11 11 11"); 58 59$t = tell F; 60# We used to have problems here before local $. worked. 61# input_line_number() used to use select and tell. When we did the 62# same, that mechanism brise. It should work now. 63is(lineno($io), "22 11 22"); 64 65{ 66 local $.; 67 $io->getline for (1 .. 5); 68 is(lineno($io), "16 16 16"); 69} 70 71is(lineno($io), "22 16 22"); 72