NAME
File::Text::CSV -- Easy access to CSV data files
SYNOPSIS
use File::Text::CSV;
# Open a CSV file with headers.
my $fh = File::Text::CSV->open( "current.csv",
{ header => 1 } );
# Read the rows.
while ( my $row = $fh->read ) {
print( $row->{Time}, ": ", $row->{Amount}, "\n");
}
# Create a new CSV file, with header row.
my $out = File::Text::CSV->create( "foo.csv",
{ header => [ qw( Time User Amount ) ],
sep_char => ";" }
);
# Print some.
$out->write( [ '13:21', 'root', 24 ] );
$out->write( { Time => '15:43', User => 'me', Amount => 42 } );
$out->close;
DESCRIPTION
File::Text::CSV is like many other CSV processing modules, but it focuses on the file side.
CSV data is a file data format, so in practice one has to work with a file, reading lines, then unpacking the data from the lines using some other module, and so on. This module combines all that.
It uses Text::CSV_XS to handle the CSV details.
File::Text::CSV requires all rows of the CSV data to have the same number of columns.
METHODS
- open
-
$csv = File::Text::CSV::->open( $file, $opts )
open creates a new File::CSV object associated with an input file.
The named file is opened and available for further processing.
The second parameter is a hashref with options. You can pass all Text::CSV options here.
Additional options specific to this function:
- header
-
If present, it must be either an arrayref with column names, or a truth value. If the latter value is true, the column names are read from the first row of the CSV file.
- encoding
-
Encoding to open the file with. Default encoding is UTF-8, unless header processing is enabled and the file starts with a byte order mark (BOM).
- append
-
If true, new records written will be appended to the file.
- create
-
$csv = File::Text::CSV::->create( $file, $opts )
open creates a new File::Text::CSV object associated with an output file.
The named file is created and available for further processing.
The second parameter is a hashref with options. You can pass all Text::CSV_XS options here.
Additional options specific to this function:
- header
-
If present, it must be a arrayref with column names. The column names are written to the first row of the CSV file.
- encoding
-
Encoding to create the file with. Default encoding is UTF-8.
- read
-
$row = $csv->read
read reads the next row from the file, parses it into columns, and delivers the result.
When column names have been specified upon object create time, this method returns a hashref. Otherwise it behaves like read_arrayref.
- read_arrayref
-
$row = $csv->read_arrayref
read_arrayref reads the next row from the file, parses it into columns, and delivers the result as an arrayref.
- write
-
$row = $csv->write( @data ) $row = $csv->write( \@data ) $row = $csv->write( \%data )
A new row of data is assembled using the content of the supplied hash or array, and written to the file.
- close
-
$csv->close
Close the file.
SUPPORT
Bugs should be reported via the CPAN bug tracker at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File::Text::CSV
For other issues, contact the author.
AUTHOR
Johan Vromans <jv@cpan.org>.
SEE ALSO
LICENSE
Copyright (C) 2016, Johan Vromans,
This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.