1nickt has asked for the wisdom of the Perl Monks concerning the following question:
Greetings learned brethren, and special salutations to Brother Tux, to whom in particular I direct this plea for assistance.
If I read the documentation for Spreadsheet::Read correctly, I should be able to pass a string containing CSV data as the sole or the first argument to ReadData(). While the SYNOPSIS does not show an example, the doc for the function does:
... and describes the function as "Tries to convert the given file, string, or stream ..." (emphasis added).my $book = ReadData ($content);
But when I try to pass a string containing simple CSV data, I get an error. First, with parser option set as recommended in the doc:
Also trying without the parser option:perl -Mstrict -MData::Dumper -MSpreadsheet::Read -wE 'my $data=ReadDat +a("A,B,C\na,b,c",parser=>"csv",debug=>9); say Dumper $data' $Options = { 'rc' => 1, 'attr' => 0, 'dtfmt' => 'yyyy-mm-dd', 'parser' => 'csv', 'cells' => 1, 'clip' => 1, 'strip' => 0, 'debug' => 9 }; Opening CSV IO using Text::CSV_XS-1.26 CSV sep_char ',', quote_char '"' Can't locate object method "getline" via package "A,B,C a,b,c" (perhaps you forgot to load "A,B,C a,b,c"?) at /Users/nick/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl +/5.22.0/Spreadsheet/Read.pm line 517.
( ... although, interestingly, when I try that from a file, I get an error, and different from the one obtained when using parser:perl -Mstrict -MData::Dumper -MSpreadsheet::Read -wE 'my $data=ReadDat +a("A,B,C\na,b,c",debug=>9); say Dumper $data' $Options = { 'attr' => 0, 'cells' => 1, 'strip' => 0, 'rc' => 1, 'debug' => 9, 'dtfmt' => 'yyyy-mm-dd', 'clip' => 1 }; $VAR1 = undef;
$ cat SR.pl use strict; use warnings; use feature 'say'; use Data::Dumper; use Spreadsheet::Read; my $csv = do { local $/; <DATA> }; my $data = ReadData( $csv, debug => 9 ); say Dumper $data; __DATA__ A,B,C a,b,c
)perl SR.pl $Options = { 'strip' => 0, 'cells' => 1, 'rc' => 1, 'clip' => 1, 'dtfmt' => 'yyyy-mm-dd', 'attr' => 0, 'debug' => 9 }; Unsuccessful stat on filename containing newline at /Users/nick/perl5/ +perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Spreadsheet/Read.pm l +ine 849, <DATA> line 1. $VAR1 = undef;
FWIW I do have:
$ perl -MIO::Scalar -E 'say $IO::Scalar::VERSION' 2.111
Thanks, o wise ones.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Spreadsheet::Read not reading CSV data passed as string
by shmem (Chancellor) on Jul 30, 2017 at 08:24 UTC | |
by Tux (Canon) on Jul 30, 2017 at 09:12 UTC | |
by shmem (Chancellor) on Jul 30, 2017 at 09:35 UTC | |
by Tux (Canon) on Jul 30, 2017 at 09:42 UTC | |
|
Re: Spreadsheet::Read not reading CSV data passed as string
by Tux (Canon) on Jul 30, 2017 at 09:00 UTC | |
by 1nickt (Canon) on Jul 30, 2017 at 13:52 UTC | |
|
Re: Spreadsheet::Read not reading CSV data passed as string
by kevbot (Vicar) on Jul 30, 2017 at 05:53 UTC |