I would like to find and replace dates in a CSV file under the following conditions:
1) The first to columns are blank, like "","",
1a) $case[1] should not match because of the text in the first two columns
2) Each of the next 6 columns may contain dates, like in $case[0] below
2a) $case[2] should not match since all 6 columns are blank
my @case = (
'"","","","1/2/2012","","","","",="12345678"',
'"Add","New","1/1/2012","1/2/2012","","","",""="0987654"',
'"","","","","","","","",="91234567"'
);
I have used the following code, but it incorrectly matches $case[2] and impacts the script's efficiency:
my $argFind = (qr/^"","",("[\d\/]*",){6}(.*)/);
$replace = '"","","","","","","","",';
if (grep(/$argFind/,@case))
{
s/$argFind/$replace$2/ for @case;
#write file
}
The end result should be like:
$case = [
'"","","","","","","","",="12345678"',
'"Add","New","1/1/2012","1/2/2012","","","",""="0987654"',
'"","","","","","","","",="91234567"'
];
"","","1/1/11","","","","","""","","","1/2/13","","4/3/2010","","""","","","","","","","1/3/2012"Text::CSVbut it has drawn my attention to your data being strange CSV. The end of the strings is either"",="12345678"or"",""="0987654". Is either of these correct? Please explain.