perlpilot / csv Goto Github PK
View Code? Open in Web Editor NEWThis project forked from masak/csv
A parser for CSV (comma-separated values) files for Perl 6
License: Artistic License 2.0
This project forked from masak/csv
A parser for CSV (comma-separated values) files for Perl 6
License: Artistic License 2.0
Simple CSV (comma-separated values) format parser for Perl 6. use v6; use Text::CSV; say Text::CSV.parse-file('somefile.csv').perl; say Text::CSV.parse("foo,bar\nbaz,boo").perl; Oh, and the C<parse> methods take the following named parameters: (Parameters without the postcircumfix parenthesis are booleans. Just include them to set them to True. Parameters with postcircumfix parenthesis expect a parameter value.) :trim Removes whitespace on both ends of each value. :skip-header Causes the first line not to be included in the output. :strict Throws an error if a row has a different number of columns than the previous ones. :output( ) Determines the shape of the returned data structure. Allowed values are 'arrays' (the default), 'hashes', and any type object (i.e. ':output(MyType)'). When the value is 'hashes' or a type object, the first line is assumed to be a special header line, the values on that line are used as hash keys, and :skip-header is suppressed. :quote( ) Use a character for quoting other than the default of double quote '"'. Must be a single, non-space character. Must be different from separator character. :separator( ) Use a separator character other than the default of comma ','. Must be a single non new-line character. (Tabs are fine. Spaces probably aren't a good idea, but... if you want to use them, knock yourself out. Just be prepared for fragile behavior. You have been warned.) Must be different from quote character. If you see yourself regularly contravening the defaults of one or more of these parameters, it might be a good idea to instantiate the Text::CSV class, giving it the default values you want: my $parser = Text::CSV.new( :output<hashes>, :!strict ); my Hash[Str] @hashes = $parser.parse-file('somefile.csv'); Text::CSV also exports a subroutine: C<csv-write>, to convert CSV data structures back to a string. C<csv-write> supports all of the internal CSV representations provided by Text::CSV.parse. C<csv-write> expects a 2 dimensional array of CSV data in one of the configurations provided by the .parse method (Array of Array, Array of Hash or Array of Object) but also will handle a flat 1 dimension array of scalar values. use v6; use Text::CSV; my @csv = Text::CSV.parse("some,string,of,CSV,data"); my $csv-string = csv-write( @csv ); There are a few other parameters which may be useful or necessary depending on your needs and data. :header( ) An array of strings. Optional for Array mode. If provided, written as the first (header) line in the file. Mandatory for hash or object modes. For hashes, the header array is the keys to the hash. In object mode, the accessors for the object attributes. :always-quote Always quote every field in the CSV, even if it would not normally be necessary. :quote( ) Same rules as for the parser. :separator( ) Same rules as for the parser. Unless you use a mutating parameter (:trim, :skip-header, :always-quote), csv-write( Text::CSV.parse( "some,csv,string", %parameters ), %parameters ) should always return the original CSV string. Like Text::CVS.parse-file, there is a C<csv-write-file> which has all the same options and requirements as C<csv-write> but writes the CSV out to a given file name. C<csv-write-file> will overwrite an existing file without warning and has no option to append. If you need finer control, open a file handle and use C<csv-write> which returns a string. use v6; use Text::CSV; my @csv = Text::CSV.parse-file('/path/to/in.csv'); csv-write( @csv, :file('/path/to/out.csv') ); == License This module is released under Artistic 2.0. See LICENSE.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.