sloppyhack
Technical User
I am having some strange activity with the expressions I wrote. (shocking huh!) The expressions work just fine by themselves, but they act up when I try to run more than one. Is there something wrong with running multiple replacement expressions on the same line? Why would they work individually? Here is the example of the code I was trying to run. It's for converting known variations of database keys to the correct keys.
#!/user/bin/perl -w
open (DATA, "EMGatt.txt"
open (WRITE, ">CORRECTED.txt"
open (LOG, ">LOGFILE.txt"
print LOG "\n\n**************ATTRIBUTE STANDARDIZATION**************\n\n";
$line = 0;
while (<DATA>) { #the following expressions look for variations in attribute
chomp; #names, standardize, and print modifications of data to the log
++$line;
if (/(^[^\t].+\t)(([Product]* ?)(Desc)[rption.]*)\t/ig && $2 ne "Description" {
print LOG "\"$2\" was replaced with \"Description\" on line # $line\n";
s/(^[^\t].+\t)[Product]* ?Desc[ription.]*\t/\tDescription\t/ig;
}
if (/(^[^\t].+\t)((Sup[plier]* ?I[Dentification]*)|(SQ ?ID) ?[\#]?)\t/ig && $2 ne "Supplier ID" {
print LOG "\"$2\" was replaced with \"Supplier ID\" on line # $line\n";
s/(^[^\t].+\t)((Sup[plier]* ?I[dentification]*)|SQ ?ID) ?[\#]?\t/$1Supplier ID\t/ig;
}
print WRITE "$_\n";
}
#!/user/bin/perl -w
open (DATA, "EMGatt.txt"
open (WRITE, ">CORRECTED.txt"
open (LOG, ">LOGFILE.txt"
print LOG "\n\n**************ATTRIBUTE STANDARDIZATION**************\n\n";
$line = 0;
while (<DATA>) { #the following expressions look for variations in attribute
chomp; #names, standardize, and print modifications of data to the log
++$line;
if (/(^[^\t].+\t)(([Product]* ?)(Desc)[rption.]*)\t/ig && $2 ne "Description" {
print LOG "\"$2\" was replaced with \"Description\" on line # $line\n";
s/(^[^\t].+\t)[Product]* ?Desc[ription.]*\t/\tDescription\t/ig;
}
if (/(^[^\t].+\t)((Sup[plier]* ?I[Dentification]*)|(SQ ?ID) ?[\#]?)\t/ig && $2 ne "Supplier ID" {
print LOG "\"$2\" was replaced with \"Supplier ID\" on line # $line\n";
s/(^[^\t].+\t)((Sup[plier]* ?I[dentification]*)|SQ ?ID) ?[\#]?\t/$1Supplier ID\t/ig;
}
print WRITE "$_\n";
}