You asked in the CB if Text::CSV_XS could parse from a string, rather than a file. I see you've used the $csv->parse() method to do that here by using <$fh> to read the file. That works ok because you apparently don't have any embedded newlines. If you did have embedded newlines you should use $csv->getline() instead and use it directly on the $fh. You can also use getline() on a string with embedded junk without any file. This correctly shows two records of four fields each:
#!perl -w use strict; use IO::Scalar; use Text::CSV_XS; my $csv = Text::CSV_XS->new( {binary=>1} ); my $fh = new IO::Scalar; my $str = qq{aa,"b\nb","c,c",7\ndd,ee,ff,8}; $fh->open(\$str); while (my $cols = getline($fh)) { print "<$_>" for @$cols; print "\n"; } sub getline { my $cols = $csv->getline($_[0]); if (!$cols) { die $! if $!; return undef; } return (@$cols) ? $cols : undef; }

In reply to Using Text::CSV_XS to parse a string by jZed
in thread Script Hanging w/Data::Dumper and Text::CSV_XS by saberworks

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.