Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Semicolon delimited to Comma delimited

by ww (Archbishop)
on Apr 23, 2015 at 11:44 UTC ( [id://1124381]=note: print w/replies, xml ) Need Help??


in reply to Semicolon delimited to Comma delimited

Not directly re Win32::OLE (the use of which seems to me [YMMV] "the hard way to achieve your results"), but have you read perldoc perlvar (from your CLI)? It describes the List Separator.

You can read about the Decimal Separator in perldoc perldata.

Converting commas to semicolons (and vice versa) is a trivial job with regexen; making sure that you don't convert non-delimiting instances of either is something your can read about in the results of an appropriate Super Search.

As always, the local value system recommends trying to find answers on your own rather than a posting a question in the form of yours... and rejecting use of well-established (tried-and-true) modules is not likely to enhance the response.

Update: Forgot to mention: Super_Search can also find nodes|threads like Thousand and decimal separators with Spreadsheet::WriteExcel.

Replies are listed 'Best First'.
Re^2: Semicolon delimited to Comma delimited
by swatzz (Novice) on Apr 23, 2015 at 12:05 UTC

    Thank you for your kind words! I would not be so dumb as to not thoroughly search before i post a question(of course there is always the 2% probability of missing out on some hint or answer given somewhere). If i were looking for Spreadsheet::WriteExcel, I would not post the question either. But if i were to change all my 10 modules written using/for OLE to Spreadsheet just because i could not figure out how to turn a semi colon to comma, well that would be a bummer. Even Google could not help me with this question except for that i could use Text::CSV. I am not completely rejecting the idea of using a new package but if there were a way to do it without using the package it would be betetr for me. Thousand and decimal separators is not a prio for me more than turning a semicolon to comma! I was told by a wise monk not to try split for *.csv files.

      The solution really boils down to a choice between:

      1. use Text::CSV;
      2. Rewrite Text::CSV in your own words, and then slowly rediscover and re-solve all the unexpected tricky bits while providing support for who knows how long.

      Actually, despite my previous comment about split / join, when I wrote my own module to handle CSV, I stepped back a generation and went for character-by-character parsing, and the use of state flags to track things like quote encapsulation and line completion.

      The Text::CSV module which existed at the time was grossly underpowered and did not work on some of the simplest CSV files I'd exported from Excel. (I would be remiss to fail to point out that it has matured nicely since.)

      I was, at the time, prohibited from working on open source projects (similar to Ben Tilly) without prefacing it by an administrative and legal process that usually took 3-6 months to complete.

      I needed working code within a week, with the flexibility to add full functionality on a more relaxed schedule.

      So my home-spun CSV module was born.

      I coded it as precisely to the specifications I could find, drawing primarily from its Wiki page, and probably also RFC 4180. As is frequently noted and quoted around the Internet, the CSV standard is not perfectly well-defined -- although in my research it became clear that more of it was sufficiently-defined than that for which most give it credit.

      I would also point out that, without surprise, Microsoft failed to adhere to one or two items that actually were in the CSV specification in its exports from Excel (whatever version we were using then), which required a few extra edge cases to be written into the module. I think at one point I was even down to considering a user-specified "Microsoft Flag" parameter to direct the parser to either follow the CSV standard or to use what worked with Microsoft Excel; not sure if I found an automated way to handle that corner case or not.

      Anyway -- I have on two occasions run into CSV files it did not properly parse, and I have bugs registered in my change control system to address them someday. Alas, it is medium-low on my priority scheme, and has not seen any attention since June of 2008.

      Plus, with Tux having written a brilliant alternative Text::CSV_XS module which, knowing Tux, probably was at least as picky about sticking to the specifications as I would have been, my motivation for fixing my own module is pretty low -- the next time I need to decode a CSV file and my own module doesn't handle it, I just might refactor to use Text::CSV_XS.

      Anyway, if you could show the code you currently use to parse and/or build SCSVs, someone here might be able to find a quick way to flex it up so it can switch its delimiter without a lot of effort.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1124381]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found