![]() |
|
Your skill will accomplish what the force of many cannot |
|
PerlMonks |
conditional statement in substitution expressionby newbio (Beadle) |
on Aug 04, 2009 at 16:31 UTC ( #785818=perlquestion: print w/replies, xml ) | Need Help?? |
newbio has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
Example: Input: **Type_1_deiodinase** , **D1** , metabolizes different forms, **A** , **B** of thyroid hormones to control levels of T3 , the active ligand for **thyroid_hormone_receptors** , **TR** Output: **Type_1_deiodinase_(D1)** metabolizes different forms, **A_(B)** of thyroid hormones to control levels of T3 , the active ligand for **thyroid_hormone_receptors_(TR)** If I do the following: $line =~ s/\*\*([^\*]+)\*\*\s\,\s\*\*([^\*]+)\*\*(\s\,)?/**$1_($2)**/g; it merges all $1 and $2 in the sentence. However, I want to merge terms only if either of $1 or $2 contains '_'. That is in the above sentence, **Type_1_deiodinase_(D1)** and **thyroid_hormone_receptors_(TR)** are OK, while **A_(B)** is not. Is there a way to apply 'if' condition in the substitution expression above so that I can merge only those adjacent terms that contain '_'? Thanks a lot.
Back to
Seekers of Perl Wisdom
|
|