I am trying to find and splot out dates from a less effective MySQL Database.
I connect, grab the key and all the records, then want to split out those that match a pattern into day, month, and year, the put into MySQL properly. Below is the code I've written, minus my connection strings. We have no pre-y2k data here, which is why I can just slap 20 onto the front of the 2-digit year
Here is a selection of data that is going into my regex.
I connect, grab the key and all the records, then want to split out those that match a pattern into day, month, and year, the put into MySQL properly. Below is the code I've written, minus my connection strings. We have no pre-y2k data here, which is why I can just slap 20 onto the front of the 2-digit year
Code:
open(OUT, ">test.sql" ) || die "Can't open file, 'test.sql': $!\n";
$db_bdb= DBI->connect('dbi:mysql:database=contacts;host=localhost:3306', $user, $pw, { RaiseError => 1, AutoCommit => 1 });
$sel = "SELECT IssueID, Version from issueditems";
$rows = $db_bdb->selectall_arrayref($sel);
foreach $row(@$rows){
print "@$row[1]\n";
if (@$row[1] =~ m/(\d(1,))\/(\d(1,))\/(\d(1,))/){
print "I found one!\n";
$date="20$3-$2-$1";
$sql = "UPDATE issueditems SET Date = '$date' WHERE IssueID = @$row[0];";
print OUT "$sql\n";
}
}
Here is a selection of data that is going into my regex.
Code:
5/5/08
3rd 30/4/08 [COLOR=red] (Getting this one would be nice) [/color]
SAL02-404jm
3rd
26/5/08
6/5/08
6/5/08
jug07jec
8/5/08
3.23
2020554328 jan 08 [COLOR=red] Don't care about this one, info duplicated elsewhere as this is a controlled item [/color]
3rd
6/5/08
6/5/08