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

NAME

Parse::USDA::NNDB - download and parse the latest USDA National Nutrient Database

VERSION

version 0.1

SYNOPSIS

  use Parse::USDA::NNDB;
  my $usda = Parse::USDA::NNDB->new($optional_cache_dir);
  $usda->open_file( 'FD_GROUP' );
  while (my $fg = $usda->getline) {
      printf "ID: %s  DESC: %s\n", $fg->{NDB_No}, $fg->{Shrt_Desc};
  }

DESCRIPTION

Parse::USDA::NNDB is for parsing the nutrient data files made available by the USDA in ASCII format. If the files are not available, they will be automatically retrieved and extracted for you.

METHODS

new($basedir)

Creates a new Parse::USDA::NNDB object. Takes one optional argument, a path to the dir which contains the datafiles to be parsed.

open_file($table)

Call with the case-insensitive name of the file, without extension, to open. You must call this before get_line.

Returns true on success.

get_line

After open_file, keep calling this to get the next line. Each line is a hashref (see USDA docs for their meanings).

Returns undef when the file is finished or if something goes wrong.

tables

Returns a list of all the known tables/filenames.

get_columns_for($table)

Returns a list of the keys used in this file.

SEE ALSO

USDA documentation

AUTHOR

Ioan Rogers <ioan.rogers@gmail.com>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 by Ioan Rogers.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)