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

NAME

Iterator::Simple::Util::CSV - Utility to iterate over CSV data

VERSION

version 0.002

SYNOPSIS

  use Iterator::Simple::Util::CSV qw( icsv );

  # Iterate over a CSV file one line at a time
  my $it = icsv( $some_csv_file );
  my $r= $it->next; # returns an array ref

  # Same, but skip the header
  my $it = icsv( $some_csv_file, skip_header => 1 );

  # Parse the header, return each row as a hash ref keyed on the
  # header columns
  my $it = icsv( $some_csv_file, use_header => 1 );
  my $r = $it->next; # returns a hash ref

  # Skip the header, specify the column keys
  my $it = icsv( $some_csv_file, skip_header => 1, column_name => [ qw( col1 col2 col3 ) ] );
  my $r = $it->next; returns a hash ref, keys col1, col2, col3

DESCRIPTION

This module combines Iterator::Simple and Text::CSV_XS to provide a simple way of iterating over CSV files. It exports a single function, icsv that constructs an iterator:

icsv( $input, [opt => value ...] )

$input can be a filename or an IO::Handle object. If the filename is -, the iterator will read from STDIN. Options may be specified as a list or a hash reference. The options use_header, skip_header and column_names control the behaviour of this module (see the synopsis for details); any other options are passed unchanged to the Text::CSV_XS constructor.

SEE ALSO

Iterator::Simple, Text::CSV_XS.

AUTHOR

Ray Miller <raym@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Ray Miller.

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