$Yr = ($FieldA =~ /^(\d{2}).*/ and $1 > 20 ? 19 : 20).$1;
On May 14, 2004, at 8:25 AM, Rick Klement wrote:
Brian Morgan wrote:
Good evening everybody, I have been working on a small database project and have come across the need to move some data from table A to table B, the year format in table A is \d{2}\D{8} and in table B \d{4}\D{8}
Since the records in table A range from 1970 - 2004. I want to be able look at the date, and determine if it is a 2000 or 1900 date and make the appropiate date change.
So here is my sollution (long): #Pull the value out of the field #For this example I don't care about the rest of FieldA I just want the 1st 2 digits, #but I need to preserve FieldA for later use in the program.
($Yr = $FieldA) =~ s/^(\d{2}).*/$1/; if($Yr > 20){ $Yr = "19$Yr"; }else{ $Yr = "20$Yr"; }
#Concat year to FieldB
I guess I am looking for a way to combine a substitution with the if statement but haven't come up with a working solution.
Anyways, I am looking forward to see what the outcome is.
Brian
There is no need for a regex
$Yr = ($FieldA > 20 ? 1900 : 2000) + $FieldA;
Or just get $FieldB directly if you don't need a separate $Yr
$FieldB = ($FieldA < 21) + 19 . $FieldA;
-- Rick Klement