I am trying to locate some special characters within sentences marked as "\v{G}" or "\v{g}" in a HTML file to replace them with "Ǧ" and "ǧ", respectively, and save the corrected sentences in a new HTML file.
My regex (.*)\\v\{(\w)\}(.*) locate the character to replace but I cannot replace the character based on its case: the resulting file contains:
This is a sentence ǧ with a upper case G.
This is a sentence ǧ with a lower case g.
instead of:
This is a sentence Ǧ with a upper case G.
This is a sentence ǧ with a lower case g.
MWE
The HTML input file contains:
This is a sentence \v{G} with a upper case G.
This is a sentence \v{g} with a lower case g.
The perl file contains:
use strict;
use warnings;
# Define variables
my ($inputfile, $outputfile, $inputone, $inputtwo, $part1, $specialcharacter, $part2);
# Initialize variables
$inputfile = "TestFile.html";
$outputfile = 'Results.html';
# Open output file
open(my $ofh, '>:encoding(UTF-8)', "$outputfile");
# Open input file
open(my $ifh, '<:encoding(UTF-8)', "$inputfile");
# Read input file
while(<$ifh>) {
# Analyse _temp.html file to identify special characters
($part1, $specialcharacter, $part2) = ($_ =~ /(.*)\\v\{(\w)\}(.*)/);
if ($specialcharacter == "g") {
$specialcharacter = "ǧ";
}elsif ($specialcharacter == "G") {
$specialcharacter = "Ǧ";# PROBLEM
}
say $ofh "\t\t<p>$part1$specialcharacter$part2";
}
# Close input and output files
close $ifh;
close $ofh;