在 perl 脚本中出现语法错误

Getting syntax error in perl script

我正在尝试 运行 您在这个答案中看到的脚本:

best way to add license section to iOS settings bundle

我在 Xcode 中遇到语法错误。

Missing right curly or square bracket at ./acknowledgements.pl line 57, at end of line
syntax error at ./acknowledgements.pl line 57, at EOF
Execution of ./acknowledgements.pl aborted due to compilation errors.
Command /bin/sh failed with exit code 255

不确定为什么会这样。

这是我机器上的脚本:

#!/usr/bin/perl -w

use strict;

my $out = "../Settings.bundle/en.lproj/Acknowledgements.strings";
my $plistout =  "../Settings.bundle/Acknowledgements.plist";

unlink $out;

open(my $outfh, '>', $out) or die $!;
open(my $plistfh, '>', $plistout) or die $!;

print $plistfh <<'EOD';
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>StringsTable</key>
<string>Acknowledgements</string>
<key>PreferenceSpecifiers</key>
<array>
EOD

for my $i (sort glob("*.license")){

    my $value=`cat $i`;
    $value =~ s/\r//g;
    $value =~ s/\n/\r/g;
    $value =~ s/[ \t]+\r/\r/g;
    $value =~ s/\"/\'/g;
    my $key=$i;
    $key =~ s/\.license$//;

    my $cnt = 1;
    my $keynum = $key;
    for my $str (split /\r\r/, $value){

        print $plistfh <<"EOD";
        <dict>
        <key>Type</key>
        <string>PSGroupSpecifier</string>
        <key>FooterText</key>
        <string>$keynum</string>
        </dict>
        EOD

        print $outfh "\"$keynum\" = \"$str\";\n";
        $keynum = $key.(++$cnt);
     }
}

print $plistfh <<'EOD';
</array>
</dict>
</plist>
EOD
close($outfh);
close($plistfh);

我认为 heredoc 终止符 (EOD) 前面不能有空格。请删除缩进并重试。