[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MySQL and loading tables from a file.



Thanks, guys!

This has all helped out quite a bit.. no longer do I have to keep a table in
the same layout as this silly .xls.  :)

Mike

On Wed, Feb 28, 2001 at 10:12:24AM -0600, Steven Pritchard wrote:
> Jason Burke said:
> > True, however if you know that each field is enclosed in quotes
> > then you could do this =)...
> 
> If it is coming from Excel, the rules are something like this
> (borrowed from the Text::CSV documentation):
> 
>   * A field MAY be surrounded by double quotes.
>   * A field that contains a comma MUST be surrounded by double quotes.
>   * A field containing double quotes MUST be surrounded by double
>     quotes, and the embedded double quotes MUST be represented by a
>     pair of consecutive double quotes.
> 
> It's ridiculously complicated.
> 
> > For a quick write once script I like to keep things simple. =)
> 
> That sounds like a challenge.  ;-)
> 
> Seriously, I had to take a look at the Text::CSV man page.  All you'd
> need to change in the script you posted is do something like this:
> 
>     use Text::CSV;
>     my $csv=Text::CSV->new;
> 
>     while (<INPUT>) {
>         chomp;
>         $csv->parse($_) or die "Invalid input at line $.: $!\n";
>         @fields = $csv->fields();
> 
> instead of
> 
>     while (<INPUT>) {
>         chomp;
>         @fields = split /,/;
> 
> or whatever.
> 
> Basically, you're looking at an extra 3 lines to ensure correctness.
> (And, honestly, having dealt with CSV from Excel before, your script
> would probably have broken pretty badly.)
> 
> BTW, personally I'd just add the extra step to insert the DBI calls.
> If you understand SQL, DBI is ridiculously simple.
> 
> 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.