sub O_ACCMODE () { O_RDONLY | O_RDWR | O_WRONLY }
-$VERSION = "0.95";
+$VERSION = "0.96";
my $DEFAULT_MEMORY_SIZE = 1<<21; # 2 megabytes
my $DEFAULT_AUTODEFER_THRESHHOLD = 3; # 3 records
my $DEFAULT_AUTODEFER_FILELEN_THRESHHOLD = 65536; # 16 disk blocksful
$rec = <$fh>;
}
return unless defined $rec;
- if (! $self->{sawlastrec} &&
- substr($rec, -$self->{recseplen}) ne $self->{recsep}) {
+ if (substr($rec, -$self->{recseplen}) ne $self->{recsep}) {
# improperly terminated final record --- quietly fix it.
# my $ac = substr($rec, -$self->{recseplen});
# $ac =~ s/\n/\\n/g;
=head1 SYNOPSIS
- # This file documents Tie::File version 0.95
+ # This file documents Tie::File version 0.96
use Tie::File;
tie @array, 'Tie::File', filename or die ...;
filehandle, and are responsible for closing it after you have untied
the @array.
+Note that Tie::File will only close any filehandles that it opened
+internally. If you passed it a filehandle as above, you "own" the
+filehandle, and are responsible for closing it after you have untied
+the @array.
+
=head1 Deferred Writing
(This is an advanced feature. Skip this section on first reading.)
=head1 LICENSE
-C<Tie::File> version 0.95 is copyright (C) 2002 Mark Jason Dominus.
+C<Tie::File> version 0.96 is copyright (C) 2002 Mark Jason Dominus.
This library is free software; you may redistribute it and/or modify
it under the same terms as Perl itself.
=head1 WARRANTY
-C<Tie::File> version 0.95 comes with ABSOLUTELY NO WARRANTY.
+C<Tie::File> version 0.96 comes with ABSOLUTELY NO WARRANTY.
For details, see the license.
=head1 THANKS
Additional thanks to:
Edward Avis /
Mattia Barbon /
+Tom Christiansen /
Gerrit Haase /
+Gurusamy Sarathy /
Jarkko Hietaniemi (again) /
Nikola Knezevic /
John Kominetz /
#!/usr/bin/perl
+use lib '/home/mjd/src/perl/Tie-File2/lib';
my $file = "tf$$.txt";
-print "1..58\n";
+print "1..59\n";
my $N = 1;
use Tie::File;
check_contents("x", "y");
}
-# (57-58) 20020402 The modifiaction would have failed if $\ were set wrong.
+# (57-58) 20020402 The modification would have failed if $\ were set wrong.
# I hate $\.
if (setup_badly_terminated_file(2)) {
$o = tie @a, 'Tie::File', $file,
check_contents($badrec);
}
+# (59) 20030527 Tom Christiansen pointed out that FETCH returns the wrong
+# data on the final record of an unterminated file if the file is opened
+# in read-only mode. Note that the $#a is necessary here.
+# There's special-case code to fix the final record when it is read normally.
+# But the $#a forces it to be read from the cache, which skips the
+# termination.
+$badrec = "world\nhello";
+if (setup_badly_terminated_file(1)) {
+ tie(@a, "Tie::File", $file, mode => 0, recsep => $RECSEP)
+ or die "Couldn't tie file: $!";
+ my $z = $#a;
+ $z = $a[1];
+ print $z eq "hello" ? "ok $N\n" :
+ "not ok $N \# got $z, expected hello\n";
+ $N++;
+}
+
sub setup_badly_terminated_file {
my $NTESTS = shift;
open F, "> $file" or die "Couldn't open $file: $!";