Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

After several years of silence, I received maintainership on Text::CSV_XS from Jochen Wiedman.

I uploaded Text-CSV_XS-0.25 to CPAN today, but I'd still like to get feedback. I'm also open to new extensions now and comments on what I did so far.

Here's the ne ChangeLog entry:

2007-05-07 H.Merijn Brand <> (0.25) * Merijn got the maintainership - code reformat and code cleanup - renamed internal (Encode, Decode) to (Combine, Parse) to prevent misinterpretation with upcoming Unicode changes and possible name clashes - added pod check (and fixed pod) - added pod coverage and small additions to the pod. More to do in this area - renamed test to fixate the sequence - Added t/50_utf8.t - tests now use Test::More . Makefile.PL requires Test::More - checked proclaimed version compatibility . 5.9.x-64int works @31159 . 5.8.x-64int-dor works @31162 . 5.8.0-dor works . 5.6.2 works . 5.005.04 works . 5.004.05 fails - 5.005 is now prerequisite - Added missing info in docs for new () - Added meta_info () method and docs - Added keep_meta_info in new () - Added t/15_flags.t - Added test_cover make target - Added test for error_input () - Added tests for fields () and meta_info () before parse () - Added tests for ->types () as method - Added tests for deleting types (coverage now over 99%) - Added is_quoted (), is_binary () and tests - Added COPYRIGHT section to pod - Added the parse example from the pod to - Added accessor methods for internals: quote_char () et all - Added tests for the new accessor methods - Added always_quote to the missing places in the doc and in n +ew () - Changed the tests to use the accessors instead of the hash k +eys except for the ->{types} and ->{_types} - Moved to examples/

And a short summary of what is new:

$csv = Text::CSV_XS->new (); is equivalent to $csv = Text::CSV_XS->new ({ quote_char => '"', escape_char => '"', sep_char => ';,', eol => '', always_quote => 0, binary => 0, keep_meta_info => 0, }); For all of the above mentioned flags, there is an accessor +method available where you can inquire for the current value, or c +hange the value my $quote = $csv->quote_char; $csv'>binary (1); : : meta_info @flags = $csv->meta_info (); This object function returns the flags of the input to "com +bine ()" or the flags of the resultant decomposed fields of "parse ( +)", whichever was called more recently. For each field, a meta_info field will hold flags that tell something about the field returned by the "fields ()" metho +d or passed to the "combine ()" method. The flags are bitwise 'o +r'd like: 0x0001 The field was quoted. 0x0002 The field was binary. See the "is_*** ()" methods below. is_quoted my $quoted = $csv->is_quoted ($column_idx); Where $column_idx is the (zero-based) index of the column i +n the last result of "parse ()". This returns a true value if the data in the indicated colu +mn was enclused in "quote_char" quotes. This might be important fo +r data where ",20070108," is to be treated as a numeric value, and + where ","20070108"," is explicitely marked as character string da +ta. is_binary my $binary = $csv->is_binary ($column_idx); Where $column_idx is the (zero-based) index of the column i +n the last result of "parse ()". This returns a true value if the data in the indicated colu +mn contained any byte in the range [\x00-\x08,\x10-\x1F,\x7F-\ +xFF] An example for parsing CSV lines: use Text::CSV_XS; my $csv = Text::CSV_XS->new ({ keep_meta_info => 1, binary => + 1 }); my $sample_input_string = qq{"I said, ""Hi!""",Yes,"",2.34,,"1.09","\x{20ac}",}; if ($csv->parse ($sample_input_string)) { my @field = $csv->fields; foreach my $col (0 .. $#field) { my $quo = $csv->is_quoted ($col) ? $csv->{quote_char} + : ""; printf "%2d: %s%s%s\n", $col, $quo, $field[$col], $qu +o; } } else { my $err = $csv->error_input; print "parse () failed on argument: ", $err, "\n"; }

As this is probably one of the modules that is used in an enourmous range of applications, not breaking things is essential. I think I've well managed to keep the API fully backward compliant, but please report any failure ASAP.

This may sound like a simple plug for a module, but it is just extreme precaution hoping not to break anything and still manage to extend the module to the modern world.

Please enjoy!

Enjoy, Have FUN! H.Merijn

Edit: g0n - replaced pre tags with code tags

Edit: cbu - replaced the ampersand notations

In reply to Feedback welcome on Text::CSV_XS by Tux

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (6)
    As of 2017-03-24 05:19 GMT
    Find Nodes?
      Voting Booth?
      Should Pluto Get Its Planethood Back?

      Results (296 votes). Check out past polls.