Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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 <h.m.brand@xs4all.nl> (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 test.pl - 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 test.pl to examples/speed.pl

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

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, 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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [stevieb]: atcroft: "Make both hands into fists..."... is something my Ma taught me in our native lang, but I was to ignorant and young to pay attention. Thanks for that :)
    [atcroft]: stevieb: Sad to say that I only recently learned that particular trick, but I have since found it very useful.... :)
    [james28909]: ill be back with a solution eventually
    [stevieb]: it's a reminder to re-inforce it :P
    [atcroft]: james28909: That particular questions was a bit of trick, actually (depending on the country you are in). More interesting is, if you are trying to subtract from an epoch time, for instance, you might have to consider when/if DST occurs for a location,
    [atcroft]: because you may have to adjust the number of seconds you change from an epoch from 86400 (not to mention leap seconds)....
    [atcroft]: james28909: Although if your program is using a database, you might be able to "pass the buck" to the database and ask it to do the date change for you....

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (3)
    As of 2017-04-29 04:37 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      I'm a fool:











      Results (531 votes). Check out past polls.