The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


Tie::File::AnyData - Access the data of a disk file via a Perl array


       use Tie::File::AnyData;

       my $coderef = sub {
       ## Code to retrieve one by one the records from a file, for example,
        # to mimic the default Tie::File behaviour (one line <=> one record):
        # (this is the default behaviour of Tie::File::AnyData too)
                my ($fh) = @_;
                my $rec = <$fh>;
                return $rec;
       tie my @data, 'Tie::File::AnyData', $file, code => $coderef;
       ## Use the tied array...
        # ... once done:
        untie @data;


This module hacks 'Tie::File' to allow it to manage any kind of data. See the documentation of 'Tie::File' for more details on the functionality of this module.

To do so, you must provide a code reference (an anonymous subroutine) to the tie call. This code should be able to read one record of your data file per call.

There are already some modules that subclasses this one and provide examples of use of this module. For example, check the documentation for Tie::File::AnyData::Bio::Fasta or Tie::File::AnyData::MultiRecord_CSV. You can use them as guidelines to build your own subroutines and modules. If you don't know how to do that, but you are still interested in having a module that manages your format of interest, contact me and I will do my best to help you in the implementation.

This module keeps intact all the goodies that Tie::File offers (caching and memory limits, deferred writing, etc). In fact you can safely use this module with the default parameters instead of Tie::File without performance penalty.


This module accepts the same parameters that Tie::File, plus:


A reference to a subroutine that must be able to retrieve one data record per call. This subroutine must accept one parameter: an already opened filehandle (or "undef" if there are not more records). For examples, see Tie::File::AnyData::Bio::Fasta or Tie::File::AnyData::CSV.


Miguel Pignatelli

Please, send any comment to:

The most recent version of this module, should be available at CPAN.


Please report any bugs or feature requests to bug-tie-file-anydata at, or through the web interface at


You can find documentation for this module with the perldoc command:

     perldoc Tie::File::AnyData


Copyright 2007 Miguel Pignatelli, all rights reserved.

This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.


  This module comes with ABSOLUTELY NO WARRANTY.


  Thanks to C<kyle> at C<perlmonks> for suggestions during the implementation of this module