菜鸟求助(急):perl访问DB2 导出数据后进行数字和字符串的辨别并将已.开头的数字前面加0 脚本执行结果错误 那位大侠帮修改下 小弟不胜感激!!!
前面一大段是访问数据库的 我测试过了 应该没问题 主要帮看看后面的判断 谢。
DB2连接应该没问题可以导出数据但是判断后不是想要的结果 本鸟才开始学习perl 希望哪位能帮我改改脚本 非常感谢。
实际输出结果:
Update | 15:32:53 | 0
time | 00:05:00 | 0
CPU used | .476 | 0
capabilit | .3 | 0
perm | 1.304 | 0
想要的结果:
Update | 15:32:53 | 0
time | 00:05:00 | 0
CPU used | NA | 0.476
capabilit | NA | 0.3
perm | NA | 1.304
#!/usr/local/bin/perl -w
use DBI;
use strict;
# represents a DB2 alias cataloged in your DB2 database directory
# my $Database = "dbi:DB2:" + $ARGV[0];
my $Database = "dbi:DB2:TEST";
# represents the user ID used to connect to the database
# my $Username = $ARGV[1];
my $Username = "ming";
# represents the password for the user ID
# my $Password = $ARGV[2];
my $Password = "tian";
# query statement from database
# my $DBQuery = $ARGV[3];
my $DBQuery = "SELECT * FROM MONAH.HELP";
# represents the database handle returned by the connect statement
my $DBConn = DBI->connect($Database, $Username, $Password) or
die "Cannot connect: $DBI::errstr";
# to connect database and prepare the query
my $DBResult = $DBConn->prepare($DBQuery) or
die "Cannot prepare: $DBConn->errstr";
# get the result from database
$DBResult->execute() or
die "Cannot execute: $DBResult->errstr";
#my $RowCount = $DBConn->do($DBQuery);
# check the execution's return code
my $DBState = $DBConn->state;
my $SQLCode = $DBConn->err;
my $Col1;
my $Col2;
# valibles for test the value type
my $numVal;
my $strVal;
$DBResult->bind_col(1, \$Col1);
$DBResult->bind_col(2, \$Col2);
while ($DBResult->fetch) {
if ($Col2 =~ /^\.\d+$/) {
$Col2 = "0" . $Col2;
}
if ($Col2 =~ /^[0-9]+(\.[0-9]{1,100})?$/) {
# valure is a number !
$numVal = $Col2;
$strVal = "NA";
}
else {
# valure is a string !
$numVal = 0;
$strVal = $Col2;
}
print "$Col1|$strVal|$numVal\n";
}
# finished
$DBResult->finish();
# close the connection
$DBConn->disconnect();DB2连接应该没问题可以导出数据但是判断后不是想要的结果 本鸟才开始学习perl 希望哪位能帮我改改脚本 非常感谢。
实际输出结果:
Update | 15:32:53 | 0
time | 00:05:00 | 0
CPU used | .476 | 0
capabilit | .3 | 0
perm | 1.304 | 0
想要的结果:
Update | 15:32:53 | 0
time | 00:05:00 | 0
CPU used | NA | 0.476
capabilit | NA | 0.3
perm | NA | 1.304
...全文
相关推荐
完美的菜鸟编辑脚本软件.
完美的菜鸟编辑脚本软件.
Ubuntu菜鸟使用手册
Ubuntu菜鸟使用手册,适合刚入门的新手朋友,ubuntu爱好者,学习者。
tomatoND固件编译教程超级菜鸟版(依照myeyre教程
tomatoND固件编译教程超级菜鸟 转大婶的,还可以
linux下codestriker配置全攻略
本人花费一周时间完全摸索实现的在linux下用mysql和apache配置的codestriker服务器配置,过程包含N多贴图,超详细的讲解,多问题的解决,完全适合不懂任何linux的菜鸟,已经测试成功。
php新手入门pdf书籍
是刚刚接触php出道菜鸟的理想选择----php新手入门


