Package DE_EPAGES::Core::API::CSV
Provides methods for creating and parsing CSV (comma separated values) files. This module wraps Text::CSV_XS and support for unicode by default. Therefore the Text::CSV_XS::new option "binary" is always on unless explicitely disabled. All function arguments and return values are assumed to be native UTF-8 perl strings.
Example |
$aFields = ParseCSV( '/Shops/DemoShop/Products/"s k u"', { 'sep_char' => '/' } ); my $aFields = ['Shops', 'DemoShop', Products', 's k u']; print CombineCSV( $aFields, { 'sep_char' => '/' } ); my $CSV = DE_EPAGES::Core::API::CSV->new; my $fh = FileHandle->new; $fh->open( $FileName, '<:encoding(utf-8)' ) or die "Can't read $FileName: $!"; while( $aFields = $CSV->getline($fh) ) { # process record } |
@EXPORT_OK |
Functions
CombineCSV
Combines a list of fields to one CSV formatted line.
Syntax |
$Line = CombineCSV( $aFields, $hOptions ); $Line = CombineCSV( $aFields ); |
Input |
|
Return |
|
CombineCSVArray
Combines a list of lines to one CSV formatted string.
Syntax |
$Line = CombineCSVArray( $aaFields, $hOptions ); $Line = CombineCSVArray( $aaFields ); |
Input |
|
Return |
|
ParseCSV
Parses one CSV formatted line and returns the parsed fields.
Syntax |
$aFields = ParseCSV( $Line, $hOptions ); $aFields = ParseCSV( $Line ); |
Input |
|
Return |
|
ParseCSVArray
Combines a list of fields to a CSV formatted string.
Syntax |
$aaFields = ParseCSVArray( $Content, $hOptions ); $aaFields = ParseCSVArray( $Content ); |
Example |
$aaFields = ParseCSVArray( "Name,Value\nSmith,45\nSummers,21\n" ); |
Input |
|
Return |
|
combine
Combines a list of fields to one CSV formatted line.
Syntax |
$Line = $CSV->combine( $aFields ); |
Input |
|
Return |
|
converter
Returns the underlying Text::CSV_XS object.
Syntax |
$Converter = $CSV->converter; |
Return |
|
getline
Reads one record from a CSV file. Returns the parsed fields or undef on end of file.
Syntax |
$aFields = $CSV->getline( $FileHandle ); |
Input |
|
Return |
|
new
Create a CSV parser and formatter object.
Syntax |
$CSV = DE_EPAGES::Core::API::CSV->new( $hOptions ); $CSV = DE_EPAGES::Core::API::CSV->new; |
Example |
$CSV = DE_EPAGES::Core::API::CSV->new( { 'sep_char' => '/' } ); |
Input |
|
Return |
|
parse
Parses one CSV formatted line and returns the parsed fields.
Syntax |
$aFields = $CSV->parse( $Line ); |
Input |
|
Return |
|