12 Oct 2014 19:26:13 UTC
- Distribution: Text-CSV-Slurp
- Module version: 1.02
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (2)
- Testers (1157 / 2 / 0)
- KwaliteeBus factor: 0
- 70.09% Coverage
- License: perl_5
- Download (12.7KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:6 non-PAUSE users
- SEE ALSO
- COPYRIGHT AND LICENSE
Text::CSV::Slurp - Text::CSV::Slurp - convert CSV into an array of hashes, or an array of hashes into CSV
I often need to take a CSV file that has a header row and turn it into a perl data structure for further manipulation. This package does that in as few steps as possible.
I added a
createmethod in version 0.8 because sometimes you just want to create some bog standard CSV from an array of hashes.
use Text::CSV::Slurp; use strict; # load data from CSV input my $data = Text::CSV::Slurp->load(file => $filename [,%options]); my $data = Text::CSV::Slurp->load(filehandle => $filehandle [,%options]); my $data = Text::CSV::Slurp->load(string => $string [,%options]); # create a string of CSV from an array of hashes my $csv = Text::CSV::Slurp->create( input => \@array_of_hashes [,%options]);
my $slurp = Text::CSV::Slurp->new();
Instantiate an object.
my $data = Text::CSV::Slurp->load(file => $filename); my $data = $slurp->load(file => $filename);
Returns an arrayref of hashrefs. Any extra arguments are passed to Text::CSV. The first line of the CSV is assumed to be a header row. Its fields are used as the keys for each of the hashes.
my $csv = Text::CSV::Slurp->create( input => \@array_of_hashes [,%options]); my $csv = $slurp->create( input => \@array_of_hashes [,%options]); my $file = "/path/to/output/file.csv"; open( FH, ">$file" ) || die "Couldn't open $file $!"; print FH $csv; close FH;
Creates CSV from an arrayref of hashrefs and returns it as a string. All optional arguments are passed to Text::CSV except for
field_orderwhich is used to determine the fields and order in which they appear in the CSV. For example:
my $csv = Text::CSV::Slurp->create( input => \@array_of_hashes, field_order => ['one','three','two'] );
If field_order is not supplied then the sorted keys of the first hash in the input are used instead.
Test::Most - for tests only
GNU General Public License v3
Available at https://github.com/babf/Text-CSV-Slurp
To Kyle Albritton for suggesting and testing the create method
This software is copyright (c) 2014 by BABF.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Module Install Instructions
To install Text::CSV::Slurp, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Text::CSV::Slurp
For more information on module installation, please visit the detailed CPAN module installation guide.
|s||Focus search bar|
|?||Bring up this help dialog|
|g p||Go to pull requests|
|g i||go to github issues (only if github is preferred repository)|
|g a||Go to author|
|g c||Go to changes|
|g i||Go to issues|
|g d||Go to dist|
|g r||Go to repository/SCM|
|g s||Go to source|
|g b||Go to file browse|