Greetings, I'm trying to get Text::CSV's getline_hr_all to slurp an entire CSV into a data structure, but the structure appears empty. What is my mistake?

UPDATE: Allow_loose_quotes is the winner.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Text::CSV; my $file = $ARGV[0]; my $csv = Text::CSV->new ({ sep_char => '|', allow_whitespace => 1, binary => 1, eol => "|$/", allow_loose_quotes => 1, ## <--added for the win }); open my $csv_file, "<", $file or die "Cannot open [$file] [$!]"; my $headers_ref = $csv->getline($csv_file) or die "no header"; $csv->column_names($headers_ref); my $table_ref = $csv->getline_hr_all($csv_file); close $csv_file; print "headers: ".Dumper( $headers_ref ); print "table: ".Dumper( $table_ref );

A Some lines of the csv:

job_execution_id | job_status | step_name | job_params | job_instance +_id | read_count | write_count | exit_message | 625 | FAILED | parseSchemaStep | {"dataFeedURI":"\/storage\/D1200. +txt","metadataID":"meta.xml","Date":"2015-07-31","Id":"146"} | 625 | + 0 |0 | org.springframework.integration.transformer.MessageTransforma +tionException: ; nested exception is org.springframework.messaging.Me +ssageHandlingException: ; nested exception is java.io.IOException: IO +Exception encountered while retrieving metadata. at org.springframework.integration.transformer.MessageTransformingHand +ler.handleRequestMessage(MessageTransformingHandler.java:74) |

Now run it:

$ ./readjoblog.pl failedjob.csv headers: $VAR1 = [ 'job_execution_id', 'job_status', 'step_name', 'job_params', 'job_instance_id', 'read_count', 'write_count', 'exit_message' ]; table: $VAR1 = [];

Neil Watson
watson-wilson.ca


In reply to Text::CSV and getline_hr_all by neilwatson

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.