Thanks, jZed. That works. As it turns out the plugin automatically takes the first line of the file and uses it for the fieldnames. Any way to avoid that? It can't be evil enough. :)
| [reply] |
Template::Plugin::DBI is on my list of modules to check out, but I've not yet worked with it. Does it allow you to specify a \%attr in the connect? If so, then this should work:
[% USE DBI(
'dbi:CSV:',undef,undef,
{ RaiseError => 1
, csv_tables =>
{ users => { file => 'c:/projekte/vdx/daten/users.txt'
, eol => "\n"
, col_names => ['id','name']
}
}
}
) -%]
If the module doesn't support setting \%attrs in the connect string, does it allow you to pass a pre-defined $dbh? If it supports neither, that seems pretty lame. That would be an issue which impacts more than DBD::CSV. OTOH in order to support \%attrs in a template probably requires a string eval which is pretty lame also. (Please don't take this as a criticism of the module, it's more of general remark on modules that support DBI connections but don't support setting \%attrs during connection). Hmm, a thought - if the templating plugin uses YAML, it could avoid string eval. | [reply] [d/l] |