菜鸟求助(急):perl访问DB2 导出数据后进行数字和字符串的辨别并将已.开头的数字前面加0 脚本执行结果错误 那位大侠帮修改下 小弟不胜感激!!!
前面一大段是访问数据库的 我测试过了 应该没问题 主要帮看看后面的判断 谢。
#!/usr/local/bin/perl -wuse 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 statementmy $DBConn = DBI->connect($Database, $Username, $Password) or die "Cannot connect: $DBI::errstr";# to connect database and prepare the querymy $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 codemy $DBState = $DBConn->state;my $SQLCode = $DBConn->err;my $Col1;my $Col2;# valibles for test the value typemy $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();