Tie-File-AnyData-MultiRecord_CSV

NAME

Tie::File::AnyData::MultiRecord_CSV - Accessing groups of CSV records in a file via a Perl array.

SYNOPSIS

use Tie::File::AnyData::MultiRecord_CSV;

## Suppose a CSV file containing the following data:

# gene1 134123 541354 ini
# gene1 134125 614513 mid1
# gene1 164151 661451 mid2
# gene1 214315 233415 fin
# gene2 313415 614351 ini
# gene2 341513 341566 fin
# gene3 512341 665144 ini
# gene3 551645 667676 ini
# gene3 661445 777347 mid
# gene3 888513 918344 fin

tie my @data_array, 'Tie::File::AnyData::MultiRecord_CSV', $datafile or die $!; print "$data_array[0]";
# prints:
# gene1 134123 541354 ini
# gene1 134125 614513 mid1
# gene1 164151 661451 mid2
# gene1 214315 233415 fin

untie @data_array;

## All the array operations are allowed: push @data_array, $rec; ## Append a CSV records at the end of the file unshift @data_array, $rec; ## Put CSV records at the beginning of the file my $rec = pop @data_array; ## Remove the last group of CSV records of the file (assigned to $rec) my $rec = shift @data_array; ## Remove the first group of CSV records of the file (assigned to $rec) ... and so on.

DESCRIPTION

Tie::File::AnyData::MultiRecord_CSV allows the management of groups of CSV records in a file via a Perl array through Tie::File::AnyData, so read the documentation of the latter module for further details on its internals. For the management of CSV records it uses Parse::CSV.

A group of CSV records is defined by some CSV lines that have a common key field. For example, if you have the following group of CSV lines in a file:

     aa1    bb1   cc1
     aa1    bb1   cc2
     aa1    bb2   cc3
     aa1    bb2   cc4
     aa2    bb3   cc5

Then, if you take key = 0 (first field), then, the fist record would be:

     aa1    bb1   cc1
     aa1    bb1   cc2
     aa1    bb2   cc3
     aa1    bb2   cc4

With key = 1 (seconf field), the first record would be:

     aa1    bb1   cc1
     aa1    bb1   cc2

Finally, with key = 2 (third field), then, the first record would be:

aa1 bb1 cc1

PARAMETERS

This module accepts the same parameters as C<Tie::File> plus:

field_sep : The character used to separate fields in the input file (defaults to "\t").

key : A number indicating the field that defines a group of CSV lines (defaults to "0").

INSTALLATION

To install this module, run the following commands:

perl Makefile.PL
make
make test
make install

SUPPORT AND DOCUMENTATION

After installing, you can find documentation for this module with the perldoc command.

perldoc Tie::File::AnyData::MultiRecord_CSV

You can also look for information at:

Search CPAN

http://search.cpan.org/dist/Tie-File-AnyData-MultiRecord_CSV

CPAN Request Tracker:

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tie-File-AnyData-MultiRecord_CSV

AnnoCPAN, annotated CPAN documentation:

http://annocpan.org/dist/Tie-File-AnyData-MultiRecord_CSV

CPAN Ratings:

http://cpanratings.perl.org/d/Tie-File-AnyData-MultiRecord_CSV

COPYRIGHT AND LICENCE

Copyright (C) 2007 Miguel Pignatelli

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