I have an “Application.config” file, which a Unicode (as opposed to ANSI or UTF8) file, which contains something like
...
<GENERAL>
...
<FULLVERSION>18.0.13.227</FULLVERSION>
</GENERAL>
...
The following script is supposed to change that to 18.1.00.012, and did on 32-bit Perl/OS:
my ($Company, $Config);
$Company=$ENV{ProgramData}."\\Sage\\Accounts\\2012\\Application.config";
if( -f $Company)
{
$Config='';
if(open(APPCONF, "<".$Company))
{
while(<APPCONF>)
{
$Config.=$_;
}
close(APPCONF);
}
if($Config=~s/(<.F.U.L.L.V.E.R.S.I.O.N.>.).*?(<.\/.F.U.L.L.V.E.R.S.I.O.N.>.)/\1\xfa\2/mi)
{
$Config=~s/\xfa/1\x008\x00\.\x000\x001\.\x000\x000\x00\.\x000\x001\x002\x00/mi;
if(open(APPCONF, ">".$Company))
{
binmode(APPCONF);
print APPCONF $Config;
close APPCONF;
}
}
}
What happens (on 64-bit Perl) is “FULLVERSION” looks OK but “/FULLVERSION” has been completely mangled and looks like chinese.
Can anyone help?
Pete
Better yet, do not mangle XML with regex, use an XML module instead. They also understand UTF-16.
hexdump Application.bad_2.config