[sf-perl] Quick question on regular expression and substitution
Loo, Peter # PHX
Peter.Loo at source.wolterskluwer.com
Wed Jun 28 10:29:27 PDT 2006
I think I am going to have to leave it like this now that I got it
working. Here is what I did:
sub sub_createInsert($$) {
print STDERR "\n***** sub_createInsert() *****\n\n";
my ($tblName, $columnsref) = @_;
my ($sqlString, $delimCols, $bindVars, $column, @cols, @temp, $cnt);
$cnt = 0;
foreach $column (@{$columnsref}) {
$cnt++;
$timestamp[$cnt] = $cnt if ("@{$column}[1]" =~ m/timestamp/i);
$date[$cnt] = $cnt if ("@{$column}[1]" =~ m/date/i);
push (@cols, @{$column}[0]);
}
$delimCols = join(', ', @cols);
$bindVars = join ', ', ('?') x @{$columnsref};
@temp = split(/,/, $bindVars);
for (my $i=1; $i<=$cnt; $i++) {
if ($timestamp[$i]) {
$temp[$i] = "to_date(?, 'YYYY-MM-DD HH24:MM:SS')";
}
elsif ($date[$i]) {
$temp[$i] = "to_date(?)";
}
}
$bindVars = join(', ', @temp);
$sqlString = "insert into " . $tblName . " (" . $delimCols . ")
values" . " (" . $bindVars . ")";
print STDERR "RETURNING SQL STRING: $sqlString\n\n";
return($sqlString);
} #<=== (End of sub_createInsert)
Thanks.
Peter
-----Original Message-----
From: sanfrancisco-pm-bounces+peter.loo=source.wolterskluwer.com at pm.org
[mailto:sanfrancisco-pm-bounces+peter.loo=source.wolterskluwer.com at pm.or
g] On Behalf Of Rich Morin
Sent: Wednesday, June 28, 2006 10:24 AM
To: San Francisco Perl Mongers User Group
Subject: Re: [sf-perl] Quick question on regular expression and
substitution
It might be cleaner to split the string into an array, edit it, and join
it back together.
-r
--
http://www.cfcl.com/rdm Rich Morin
http://www.cfcl.com/rdm/resume rdm at cfcl.com
http://www.cfcl.com/rdm/weblog +1 650-873-7841
Technical editing and writing, programming, and web development
_______________________________________________
SanFrancisco-pm mailing list
SanFrancisco-pm at pm.org
http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
This E-mail message is for the sole use of the intended recipient(s) and
may contain confidential and privileged information. Any unauthorized
review, use, disclosure or distribution is prohibited. If you are not
the intended recipient, please contact the sender by reply E-mail, and
destroy all copies of the original message.
More information about the SanFrancisco-pm
mailing list