|
|
Choosing A Webhost: |
Re: [Boston.pm] Reading a variable CSV file with embeded newlines: msg#00013lang.perl.perl-mongers.boston
Once again, thank you all. This helps alot. --Alex On 6/8/07, Guillermo Roditi <groditi-Re5JQEeQqe8AvxtiuMwx3w@xxxxxxxxxxxxxxxx> wrote: > Oops. i went too fast. thats a preprocess command that i use with > App::Cmd (highly recommended by the way) $args is an arrayref of > filepaths read_file is provided by File::Slurp the regex is what you > are looking for. The problem sucks since its a badly formatted file, > but i normally just run that as a preprocessor and then use CSV_XS > > > > > On 6/8/07, Ben Tilly <btilly-Re5JQEeQqe8AvxtiuMwx3w@xxxxxxxxxxxxxxxx> wrote: > > On 6/8/07, Gyepi SAM <gyepi-diegcgK5yUWD2xfEYUDpZg@xxxxxxxxxxxxxxxx> wrote: > > > On Fri, Jun 08, 2007 at 03:26:56PM -0400, Alex Brelsfoard wrote: > > > > I have a CSV file where each line may NOT have the same number of > > > > fields. > > > > One item per line. > > > > > > xSV is line oriented: as long as each line is well formed it should be > > > parsed > > > correctly. Making sense of the data may be more difficult though. > > > > Yup. > > > > > > But occasionally a field in an item will have one or more newlines in > > > > it. > > > > How can I break this up correctly? > > > > > > Embedded newlines are OK as long as the field is quoted. However, not all > > > tools will parse the field correctly. Last time I checked, Text::CSV and > > > Text::CSV_XS do not. I suspect Text::xSV will be better behaved. There are > > > other, non Perl, tools that should work fine as well. > > > > I had thought that Text::CSV did handle that case, but I just checked > > and it does not. :-( > > > > Text::xSV does this correctly, though not speedily. Here is sample code: > > > > use strict; > > use Text::xSV; > > > > my $csv = Text::xSV->new( > > filename => "foo.csv", > > row_size_warning => 0, # Stop warnings for variable size rows. > > ); > > while (my @row = $csv->get_row()) { > > # Do something here. > > } > > > > Cheers, > > Ben > > > > _______________________________________________ > > Boston-pm mailing list > > Boston-pm-PqP1ghmmPMdAfugRpC6u6w@xxxxxxxxxxxxxxxx > > http://mail.pm.org/mailman/listinfo/boston-pm > > >
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | [Boston.pm] Need some help with MASON setup., Steven W. Orr |
|---|---|
| Next by Date: | [Boston.pm] Reminder: Tech Meeting Tomorrow, Tuesday, June 12, at MIT, Ronald J Kimball |
| Previous by Thread: | Re: [Boston.pm] Reading a variable CSV file with embeded newlines, Guillermo Roditi |
| Next by Thread: | [Boston.pm] Need some help with MASON setup., Steven W. Orr |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |