[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: MySQL and loading tables from a file.
True, however if you know that each field is enclosed in quotes
then you could do this =)...
# perl -pi -e "s/\",/\"~/" ./filename.csv
which should replace all outside commas with tildes <sp? - the
~ character =>. Then you could do this without worrying too much..
@fields = split(/~/, $_);
or you could split on the quotes and then go through and drop out
any quote-comma-quote sequence in the array.
For a quick write once script I like to keep things simple. =)
Steven Pritchard wrote:
> Jason Burke said:
> > @fields = split(/,/, $_); # I don't think I need to escape the , here.
> Unfortunately, that's overly simplistic. Excel likes to do things
> "a field","a field that's really, really hard to parse",etc.
> If you just split on /,/, you'll get
> (q/"a field"/, q/"a field that's really/, q/really hard to parse"/,
> Not exactly right, huh?
> It would probably be better to look at either the DBD::CSV module or
> the Text::CSV module.
> email@example.com | Southern Illinois Linux Users Group
> (618)398-7320 | See web site for meeting details.
> Steven Pritchard | http://www.silug.org/
> To unsubscribe, send email to firstname.lastname@example.org with
> "unsubscribe luci-discuss" in the body.
To unsubscribe, send email to email@example.com with
"unsubscribe luci-discuss" in the body.