http://www.perlmonks.org?node_id=989757


in reply to Re^2: DBD::CSV::prepare() problems
in thread DBD::CSV::prepare() problems

Because you use the file => $filename approach, you do not use the case-insensitiveness from SQL::Statement.

I do not think you should define csv_eol

When on Windows *and* other OS's, do not use $dir."/".$file, but use File::Spec.

When in doubt about casing, use something like

chdir $f_path; foreach my $file_name (glob "*.*") { lc $file_name eq lc $csvfile or next; $csv_file = $file_name; last; } my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_dir => $f_path, f_ext => ".csv/r", f_encoding => "utf-8", f_schema => undef, RaiseError => 1, PrintError => 1, }); $cellh->{csv_tables}{cells} = { file => $csv_file }; my $sth = $sbh->prepare ("select * from cells"); $sth->execute; print "fields: @{[@{$sth->{NAME_lc}}]}\n";

untested, but should work.


Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^4: DBD::CSV::prepare() problems
by Anonymous Monk on Aug 26, 2012 at 11:29 UTC

    When on Windows *and* other OS's, do not use $dir."/".$file, but use File::Spec.

    Go ahead and use / on every OS you have

      Go ahead and use / on every OS you have

      Nonsense! Not every OS uses the forward slash (/) as path separator.

      DOS and Windows (and OS/2, I think) allow to use both backslash (\) and forward slash, so you can use the forward slash on Windows, except when you try to use external tools that expect that you only use the backslash.

      On a classic, non-X MacOS, you will fail miserably because MacOS uses single colons (:).

      Same game, different rules with VMS: / works only in Unix emulation, the native interface uses single colons, double colons (C<::>), square brackets ([]), angle brackets (<>), periods (C<.>), and semicolons (C<;>) to separate the parts of a fully qualified file name.

      File::Spec is not perfect, but it still is better than simply using the forward slash everywhere.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        Nonsense! Not every OS uses the forward slash (/) as path separator.

        So what, the OP doesn't have one of those

        On a classic, non-X MacOS, you will fail miserably because MacOS uses single colons (:).

        No you won't, you'll get a nice error message, and then you cheerfully fix it -- or it will cheerfully work and you'll get a file with slashes in the name -- no misery anywhere

        Same game, different rules with VMS ...

        Same ol' same ol'

        File::Spec is not perfect, but it still is better than simply using the forward slash everywhere.

        File::Spec is great, Path::Class is better, but using forward slashes on unix/linux/windows will work 99% of the time