Hi All, I don't use perl very often and TEXT::CSV_XS is kicking my ass.

I would use Text::CVS which was working great for me except that it doesn't handle french characters.

I also have to use a different seperator because some field have multiple comma separated characters. This is the data:

374|Mike who|kelticjan|mike@someemail.com|23/2/2012 10:57:32|0|0|Mike| +Clements|90 Street Ave|Halifax|New Brunswick|1t5 7y7|516-555-5555|lol + Transportation Inc.|a||a||||a,b,c,d,e,g,h,i,j,k||a|a|a|a|a,b,c,d,e|I +dle time / miles per gallon|a,b,c||b||a,d,f,g,h|

this is what I am trying to do to parse it and print it out with no separator character.

#!/usr/bin/perl use Text::CSV_XS; my $csv = Text::CSV_XS->new ({ quote_char => '"', escape_char => '"', sep_char => "|", eol => $\, always_quote => 0, quote_space => 1, quote_null => 1, quote_binary => 1, binary => 1, keep_meta_info => 0, allow_loose_quotes => 0, allow_loose_escapes => 0, allow_whitespace => 0, blank_is_undef => 0, empty_is_undef => 0, verbatim => 0, auto_diag => 0, }) or die "Cannot use CSV: ".Text::CSV_XS->error_diag (); open my $FH, "<:encoding(utf8)", "test.csv" or die "test.csv: $!" +; while (my $line = $csv->getline ($FH)){ if ($csv->parse (@$line)) { my @field = $csv->fields; foreach my $col (0 .. $#field) { print $field[$col], "\n" ; } } else { print STDERR "parse () failed on argument: ", $csv->error_input, "\n"; $csv->error_diag (); } }

this is the output:

374

I've tried a bunch of ways and seem to be confused ... I'd appreciate some help.

Thanks Mike


In reply to Re: HELP :: Text::CSV_XS separator character tab by mlaro
in thread Text::CSV_XS separator character tab by webchalkboard

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.