Tie::File 0.96 review

Download
by rbytes.net on

Tie::File can access the lines of a disk file via a Perl array. SYNOPSIS # This file documents Tie::File version 0.96

License: Perl Artistic License
File size: 66K
Developer: Mark Jason Dominus
0 stars award from rbytes.net

Tie::File can access the lines of a disk file via a Perl array.

SYNOPSIS

# This file documents Tie::File version 0.96
use Tie::File;

tie @array, 'Tie::File', filename or die ...;

$array[13] = 'blah'; # line 13 of the file is now 'blah'
print $array[42]; # display line 42 of the file

$n_recs = @array; # how many records are in the file?
$#array -= 2; # chop two records off the end


for (@array) {
s/PERL/Perl/g; # Replace PERL with Perl everywhere in the file
}

# These are just like regular push, pop, unshift, shift, and splice
# Except that they modify the file in the way you would expect

push @array, new recs...;
my $r1 = pop @array;
unshift @array, new recs...;
my $r2 = shift @array;
@old_recs = splice @array, 3, 7, new recs...;

untie @array; # all finished

Tie::File represents a regular text file as a Perl array. Each element in the array corresponds to a record in the file. The first line of the file is element 0 of the array; the second line is element 1, and so on.

The file is not loaded into memory, so this will work even for gigantic files. Changes to the array are reflected in the file immediately. Lazy people and beginners may now stop reading the manual.

Requirements:
Perl

Tie::File 0.96 keywords