Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: [Boston.pm] Reading a variable CSV file with embeded newlines: msg#00013

lang.perl.perl-mongers.boston

Subject: Re: [Boston.pm] Reading a variable CSV file with embeded newlines

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>
Google Custom Search

Recently Viewed:
user-groups.jax...    php.zend.framew...    os.solaris.open...    web.quixote.use...    java.openjdk.ho...    ietf.secmech/20...    gnu.glpk/2004-0...    recreation.cars...    network.smokepi...    linux.drivers.i...    cms.opencms.dev...    fonts.gfontview...    text.xml.soap.u...    voip.nist-sip/2...    debian.ports.hp...    xfree86.interna...    science.biology...    qnx.openqnx.dev...    mail.sylpheed.c...    busybox/bios/20...    emulators.kvm.s...    hardware.openco...    apple.fink.begi...    kde.german/2006...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive 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

Navigation