I'm using Strawberry Perl 5.14.2 on MS Windows. The following code runs fine on Linux Perl 5.10.1 but fails on MS Windows. I need to update it to run on both.
sub read_dict {
open F, "<:utf8", "$dictfile" || die "Dictonary file $dictfile not found";
while (<F>) {
chomp;
s/^ *//;
split;
$freq{$_[1]} = $_[0];
$header = substr($_[1],0,$wd);
if ($freq{"m,$header"}) {
if ($freq{"m,$header"} < length($_[1])) {
$freq{"m,$header"} = length($_[1]);
}
} else {
$freq{"m,$header"} = length($_[1]);
}
$freq{total} += $_[0];
}
close(F);
}
It finds and parses $dictfile on MS Windows, but fails to accumulate the $freq{total}, which causes a divide-by-zero error elsewhere. $dictfile is a weighted dictionary with data that looks like this:
8 永垂不朽
8 震耳欲聋
85 罗马里奥
891 澳大利亚
9 埃芬贝格
My troubleshooting between the two platforms shows it's failing either at split; or the following line, but I don't know enough Perl to fix it. Does the code need to be changed, or should I start Perl with a specific command-line option?
Thanks.