summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/dist/Tie-File/t/12_longfetch_rs.t
blob: 6fa3298b0108673a1e627644c9a5a4fcf806f819 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl
#
# Make sure we can fetch a record in the middle of the file
# before we've ever looked at any records before it
#
# (tests _fill_offsets_to() )
#

use strict;
use warnings;

my $file = "tf12-$$.txt";
my $data = "rec0blahrec1blahrec2blah";

print "1..5\n";

my $N = 1;
use Tie::File;
print "ok $N\n"; $N++;

open F, '>', $file or die $!;
binmode F;
print F $data;
close F;

my @a;
my $o = tie @a, 'Tie::File', $file, autochomp => 0, recsep => 'blah';
print $o ? "ok $N\n" : "not ok $N\n";
$N++;

my $n;

# 3-5
for (2, 1, 0) {
  print $a[$_] eq "rec${_}blah" ? "ok $N\n" : "not ok $N # rec=$a[$_] ?\n";
  $N++;
}

END {
  undef $o;
  untie @a;
  1 while unlink $file;
}