Ray Miller


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


version 0.002


  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


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.


Iterator::Simple, Text::CSV_XS.


Ray Miller <raym@cpan.org>


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.