[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. =)

Jason

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
> like
>
>     "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"/,
>      q/etc./)
>
> Not exactly right, huh?
>
> It would probably be better to look at either the DBD::CSV module or
> the Text::CSV module.
>
> Steve
> --
> steve@silug.org           | 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 majordomo@luci.org with
> "unsubscribe luci-discuss" in the body.

-
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.