Perl Monk, Perl Meditation | |
PerlMonks |
Re: Reading escaped data from a CSVby hanenkamp (Pilgrim) |
on Nov 14, 2003 at 22:40 UTC ( [id://307232]=note: print w/replies, xml ) | Need Help?? |
First my rant: No offense monks, but some of the answers I've read to this question are kind of pathetic. I don't care whether or not there is a module or not, but sometimes it is helpful to know the technique. Sheesh. Feel free to make comments about using modules, but at least give him/her some direction besides, "No one does this anymore, just use the module or forget it!" Reinventing the wheel is a time-honored process for learning. Nice way to be rude to a potential JAPH. Anonymous, my first suggestion is to browse CPAN for the modules that have been mentioned already by others. At http://search.cpan.org/ you can view the documentation of modules and then click on the "Source" links to view the actual source. Then, you can see how the module author has done it. If you are interested in really doing this yourself, which I, like the others, would not recommend. You can use a negative lookup in a split to use escaped commas:
Another solution is to use a character which you do not allow in your strings, which is why characters like ^ or ~ or | are often used as delimiters in CSV files. The most common solution, however, is to use quotes around strings to escape an entire string. That is, commas are only available for splitting outside of quotes. This is difficult enough that I don't, off-hand, have a simple solution, though I've seen a few...for this, I would definitely suggest browsing the source of a pertinent module.
In Section
Seekers of Perl Wisdom
|
|