This rocks!
my $dbh = DBI->connect ("dbi:CSV:", undef, undef, {
RaiseError => 1,
PrintError => 1,
f_dir => ".",
f_schema => undef,
f_ext => ".csv/r",
f_encoding => "utf8",
});
Any objections to me committing that?
--8<---
--- /pro/3gl/CPAN/DBI-svn/lib/DBD/File.pm 2009-12-03 20:58:35.000000000
+0100
+++ /pro/lib/perl5/site_perl/5.12.0/i686-linux-64int-ld/DBD/File.pm
2010-04-21 16:06:12.000000000 +0200
@@ -163,6 +163,7 @@ sub connect ($$;$$$)
f_schema => 1, # schema name
f_tables => 1, # base directory
f_lock => 1, # Table locking mode
+ f_encoding => 1, # Encoding of the file
};
$this->{sql_valid_attrs} = {
sql_handler => 1, # Nano or S:S
@@ -724,7 +725,14 @@ sub open_table ($$$$$)
$safe_drop or croak "Cannot open $file: $!";
}
}
- $fh and binmode $fh;
+ if ($fh) {
+ if (my $enc = $data->{Database}{f_encoding}) {
+ binmode $fh, ":encoding($enc)";
+ }
+ else {
+ binmode $fh;
+ }
+ }
if ($locking and $fh) {
my $lm = defined $data->{Database}{f_lock}
&& $data->{Database}{f_lock} =~ m/^[012]$/
@@ -961,6 +969,11 @@ But see L</"NOWN BUGS"> below.
=back
+=item f_encoding
+
+With this attribute, you can set the encoding in which the file is opened.
+This is implemented using C<binmode $fh, ":encoding(<f_encoding>)">.
+
=head2 Driver private methods
=over 4
-->8---
--
H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/
using 5.00307 through 5.12 and porting perl5.13.x on HP-UX 10.20, 11.00,
11.11, 11.23, and 11.31, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3.
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/
http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/