【发布时间】:2009-12-31 02:09:11
【问题描述】:
此脚本中的函数“REGEX()”和“TRIM()”无法正常工作。 REGEX 函数总是返回 true,TRIM 函数返回“trim_char”,而不是修剪后的字符串。 (当我用 FROM 而不是“,”编写 TRIM 函数时,我收到一条错误消息。)
#!/usr/bin/perl
use warnings;
use strict;
use 5.010;
use DBI;
my $dbh = DBI->connect( "DBI:CSV:", undef, undef, { RaiseError => 1, AutoCommit => 1 } );
my $table = 'artikel';
my $array_ref = [ [ 'a_nr', 'a_name', 'a_preis' ],
[ 12, 'Oberhemd', 39.80, ],
[ 22, 'Mantel', 360.00, ],
[ 11, 'Oberhemd', 44.20, ],
[ 13, 'Hose', 119.50, ],
];
$dbh->do( "CREATE TEMP TABLE $table AS IMPORT(?)", {}, $array_ref );
say "";
# purpose : test if a string matches a perl regular expression
# arguments : a string and a regex to match the string against
# returns : boolean value of the regex match
# example : ... WHERE REGEX(col3,'/^fun/i') ... matches rows
# in which col3 starts with "fun", ignoring case
my $sth = $dbh->prepare( "SELECT a_name FROM $table WHERE REGEX( a_name, '/^O/')" );
$sth->execute();
$sth->dump_results();
say "\n";
# TRIM ( [ [LEADING|TRAILING|BOTH] ['trim_char'] FROM ] string )
$sth = $dbh->prepare( "SELECT a_name, TRIM( TRAILING 'd', a_name ) AS new_name FROM $table" );
$sth->execute();
$sth->dump_results();
say "";
$dbh->disconnect();
有人给点建议吗?
编辑:
DBD::SQLite:1.25
DBD::ExampleP : 12.010007
DBD::海绵 : 12.010002
DBD::CSV : 0.26
DBD::Gofer : 0.011565
DBD::DBM : 0.03
DBD::代理:0.2004
DBI : 1.609
DBD::文件:0.37
SQL::语句:1.23
【问题讨论】:
-
你有最新的 DBI、DBD::CSV、SQL::Statement 吗?