in reply to Re: Double quotes in CSV using Text::CSV
in thread Double quotes in CSV using Text::CSV

it's works, but always_quote=>1 it is no good. necessary for me:
$csv->print(\*STDOUT, ["1","2",""]); __END__ 1,2,""

Replies are listed 'Best First'.
Re^3: Double quotes in CSV using Text::CSV
by Corion (Patriarch) on May 19, 2015 at 12:11 UTC

    I don't think this is possible with Text::CSV or Text::CSV_PP. The documentation of Text::CSV hints at maybe using ->is_quoted or the metadata information, but at least the implementation in Text::CSV_PP does not so any conditional quoting.

Re^3: Double quotes in CSV using Text::CSV
by Tux (Canon) on May 20, 2015 at 08:52 UTC

    That wasn't too difficult. See this commit. It will be available in version Text::CSV_XS version 1.18, but you can get it from github already.

    $ perl -Mblib -MText::CSV_XS \ ? -E'my $csv = Text::CSV_XS->new ({ quote_empty => 1 });' \ ? -E'$csv->combine (1, undef, "", " ", 2);' \ ? -E'say $csv->string' 1,,""," ",2

    update I forgot I already implemented this in the perl6 version Text::CSV.


    Enjoy, Have FUN! H.Merijn
Re^3: Double quotes in CSV using Text::CSV
by Anonymous Monk on May 19, 2015 at 12:15 UTC

    Your original post did not specify that. Please see I know what I mean. Why don't you? and How do I post a question effectively? Could you please show some sample input and output that is representative of what you are trying to print? Otherwise, we're just guessing at the correct answer.

    use Text::CSV; my $csv = Text::CSV->new({binary=>1,eol=>$/, quote_char=>undef,escape_char=>undef}); $csv->print(\*STDOUT, ["1","2",'""']); __END__ 1,2,""
      quote_char=>undef,escape_char=>undef helps Thanks
Re^3: Double quotes in CSV using Text::CSV
by Tux (Canon) on May 19, 2015 at 19:04 UTC

    WHY? Why can 1 and 2 not be quoted? I could add quote_empty => 1 to Text::CSV_XS, but you've shown me no good reason so far.

    "1","2","" is just as valid CSV as 1,2,"" and 1,2, are and on parsing they'll all yield the same data (unless parsing options cause different rules).


    Enjoy, Have FUN! H.Merijn

      Two ideas:

      Saving bytes
      Yes, despite having Gigabit networks and Terabyte harddisks, some people discuss every single byte.
      A primitive type system on top of CSV
      Unquoted numbers represent numbers, quoted numbers are just strings (as in JSON).

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        #3: The homework assignment says not to quote them.

        Aaron B.
        Available for small or large Perl jobs and *nix system administration; see my home node.