Buckaroo Buddha has asked for the wisdom of the Perl Monks concerning the following question:

I've got a data set that looks somewhat like this:
|value 1|value two|"|Value 3 was "NULL"|2001/06/06|

It is a very large file and It is being imported daily into an MS-SQL server by a SAS script

unfortunately, in this case SAS can't handle quotes very well. So I must clean the file before SAS gets its ruddy little paws on it.

I had hoped to do a quick and sexy inline thing to the effect of:

perl -pi.bak -e "s/\|\"\|/\|\|/g" filename

sweet ... unfortunately there are too many special characters for an inline to work
then I moved on to
open OUTFILE, ">>@ARGV[0].dat"; while (<>) { $_ =~ s/\|\"\|/\|\|/g; print OUTFILE $_; } close OUTFILE;

sweet, it works! no problem

but now i've found that unmatched quotes still happen at other places in the data. I must instead come up with a way of saying:

"if you find a | before you find a second quote you must substitute it for a blank space"

now one way would be to:

while (<>) { split /\|/; my $output = "|"; foreach my $value (@_) { if ($value =~ m/"{1}/) { $value =~ s/"//g; } $output =. $value . "|"; } print $output; }
the two questions i have are:
1) is there a better way to do this? I figure regex's are so powerful that this could probably be done in one line. if I went out and bought that O'reilly book on mastering regular expressions do you think i'd be able to write that one myself?

2) is there a way to match any ODD number of quotes as opposed to just one quote?