Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: How can I read a file that is comma delimited but includes a comma in the string?

by Anonymous Monk
on May 28, 2003 at 00:00 UTC ( #261141=note: print w/replies, xml ) Need Help??


in reply to Re: How can I read a file that is comma delimited but includes a comma in the string?
in thread How can I read a file that is comma delimited but includes a comma in the string?

if all fields were in double quotes then how could I include it and not print the quotes?
  • Comment on Re: Re: How can I read a file that is comma delimited but includes a comma in the string?

Replies are listed 'Best First'.
Re: Re: Re: How can I read a file that is comma delimited but includes a comma in the string?
by Ovid (Cardinal) on May 28, 2003 at 00:13 UTC

    Directly from the POD of Text::CSV_XS:

    require Text::CSV_XS; my $csv = Text::CSV_XS->new; my $column = ''; my $sample_input_string = '"I said, ""Hi!""",Yes,"",2.34,,"1.09" +'; if ($csv->parse($sample_input_string)) { my @field = $csv->fields; my $count = 0; for $column (@field) { print ++$count, " => ", $column, "\n"; } print "\n"; } else { my $err = $csv->error_input; print "parse() failed on argument: ", $err, "\n"; } my @sample_input_fields = ('You said, "Hello!"', 5.67, 'Surely', '', '3.14159'); if ($csv->combine(@sample_input_fields)) { my $string = $csv->string; print $string, "\n"; } else { my $err = $csv->error_input; print "combine() failed on argument: ", $err, "\n"; }

    Cheers,
    Ovid

    New address of my CGI Course.
    Silence is Evil (feel free to copy and distribute widely - note copyright text)

Re: Re: Re: How can I read a file that is comma delimited but includes a comma in the string?
by arturo (Vicar) on May 28, 2003 at 00:05 UTC

    The Perl module Text::CSV can be really helpful here, since it's designed to handle things like quotes for you.

    If not P, what? Q maybe?
    "Sidney Morgenbesser"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://261141]
help
Chatterbox?
[erix]: and now you are agnostic?
[james28909]: arunbear, your picking bits of history to fit your own narrative. right now, humans are smarter than in any of those times.
[james28909]: in order for there to be a mutation, there has to be a universe with laws setup that even allow a mutation.
[james28909]: everything past the first two things you piked from my posts are irrelevant to me and my beliefs. they are side effects.
[james28909]: two or three. if it has to do with how humans are handling said situations, then that is after they were able to evolve into those problems. agnostic means only believe with evidence. i took that from a tyson video
[james28909]: and it seems that racism suggest that there is indeed a better race, but that is for evolution to decide
[1nickt]: "right now, humans are smarter than in any of those times": define "smart"
[erix]: ah, now you're appraoch downvote-territory ;)

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2017-12-15 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (433 votes). Check out past polls.

    Notices?