Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running multiple replacement expressions on an input line 1

Status
Not open for further replies.

sloppyhack

Technical User
Apr 17, 2001
111
0
0
US
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 &quot;Description&quot;) {
print LOG &quot;\&quot;$2\&quot; was replaced with \&quot;Description\&quot; on line # $line\n&quot;;
s/(^[^\t].+\t)[Product]* ?Desc[ription.]*\t/\tDescription\t/ig;
}
if (/(^[^\t].+\t)((Sup[plier]* ?I[Dentification]*)|(SQ ?ID) ?[\#]?)\t/ig && $2 ne &quot;Supplier ID&quot;) {
print LOG &quot;\&quot;$2\&quot; was replaced with \&quot;Supplier ID\&quot; on line # $line\n&quot;;
s/(^[^\t].+\t)((Sup[plier]* ?I[dentification]*)|SQ ?ID) ?[\#]?\t/$1Supplier ID\t/ig;
}
print WRITE &quot;$_\n&quot;;
}
 
it may be that since you're doing global searches in the conditionals statements that it is remembering your current position in the string and therefore messing up, but i don't think this is it. regardless, you can make the conditionals not global and it won't affect anything negatively.

it's a guess, i'll think about it more though. &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
You may be right stillflame. I'd take the 'g' option off the searches and try it again. After all, it only matters if it's on the line at all.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
You guys kick ass!!! That was it. Seems to work ok now. This is my first large script and you don't now how much it helps to have technical consultants such as yourselves! Stillflame you have especially helped me with this project.

CHEERS!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top