**_Write a program_**

london1854 Posted messages 3 Status Member -  
[Dal] Posted messages 6122 Registration date   Status Contributor Last intervention   -
Bonjour,

I have a program to create in Perl that highlights in bold and yellow the final sequence "ité" in the declined forms of nouns (examples: familiarité/NOM/familiarité).
The tag to be inserted in the substitution function to highlight the sequence 'ité' in yellow and bold is as follows:

<b style="background:yellow;">ité</b>
Here is the program I created:

print "<x-html><html><body>\n"; while(<>) { chomp; $line=$_; $line =~ s/NOM/ite\/<b style="background:yellow;">ité</b>/g; print "$line <br> \n"; } print "</body></html></x-html>\n"
;

I have a problem because this program does not work, could someone explain how to make it work correctly and achieve the requested result?
Thank you in advance.
EDIT: Added code tags (syntax highlighting).
Explanations available here: HERE

Thank you for keeping this in mind in your future messages.

1 answer

[Dal] Posted messages 6122 Registration date   Status Contributor Last intervention   1 108
 
Hi,

The slash must be escaped in the regexp because it is the default delimiter for its different parts. You only do it for one slash, and not for the one contained at the end on "</b>" (which you should want to escape logically).

If we correct your regexp by escaping "</b>" like this "<\/b>", the regexp
s/NOM/ite\/<b style="background:yellow;">ité<\/b>/g
means that:

- you are searching for all occurrences of "NOM"
- you are replacing them with "ite/<b style="background:yellow;">ité</b>"

In fact, I doubt that this is really what you want to do.

The simplest thing is for you to provide several complete raw text examples that could be in $ligne and give the expected result for each.

Dal
0