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:

my $book = ReadData ($content);
... and describes the function as "Tries to convert the given file, string, or stream ..." (emphasis added).

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:

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.
Also trying without the parser option:
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;
( ... although, interestingly, when I try that from a file, I get an error, and different from the one obtained when using parser:
$ 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.


The way forward always starts with a minimal test.

In reply to Spreadsheet::Read not reading CSV data passed as string by 1nickt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.