📄 42_offset.t
字号:
#!/usr/bin/perl# 2003-04-09 Tels: test the offset method from 0.94use Test::More;use strict;use File::Spec;use POSIX 'SEEK_SET';my $file = "tf$$.txt";BEGIN { $| = 1; if ($ENV{PERL_CORE}) { # testing with the core distribution @INC = ( File::Spec->catdir(File::Spec->updir, 't', 'lib') ); } unshift @INC, File::Spec->catdir(File::Spec->updir, 'lib'); chdir 't' if -d 't'; print "# INC = @INC\n"; plan tests => 24; use_ok ('Tie::File'); }$/ = "#"; # avoid problems with \n\r vs. \nmy @a;my $o = tie @a, 'Tie::File', $file, autodefer => 0;is (ref($o), 'Tie::File');is ($o->offset(0), 0, 'first one always there');is ($o->offset(1), undef, 'no offsets yet');$a[0] = 'Bourbon';is ($o->offset(0), 0, 'first is ok');is ($o->offset(1), 8, 'and second ok');is ($o->offset(2), undef, 'third undef');$a[1] = 'makes';is ($o->offset(0), 0, 'first is ok');is ($o->offset(1), 8, 'and second ok');is ($o->offset(2), 14, 'and third ok');is ($o->offset(3), undef, 'fourth undef');$a[2] = 'the baby';is ($o->offset(0), 0, 'first is ok');is ($o->offset(1), 8, 'and second ok');is ($o->offset(2), 14, 'and third ok');is ($o->offset(3), 23, 'and fourth ok');is ($o->offset(4), undef, 'fourth undef');$a[3] = 'grin';is ($o->offset(0), 0, 'first is ok');is ($o->offset(1), 8, 'and second ok');is ($o->offset(2), 14, 'and third ok');is ($o->offset(3), 23, 'and fourth ok');is ($o->offset(4), 28, 'and fifth ok');$a[4] = '!';is ($o->offset(5), 30, 'and fifth ok');$a[3] = 'water';is ($o->offset(4), 29, 'and fourth changed ok');is ($o->offset(5), 31, 'and fifth ok');END { undef $o; untie @a; 1 while unlink $file;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -