[D]Perl小程序调不通Perl code$^I.bakUnless (open IN, a.txt) {die can not open file a.txt\n
[D]Perl小程序调不通
- Perl code
$^I=".bak";Unless (open IN, "<a.txt") {die "can not open file a.txt\n";}Unless (open OUT,">out.txt") {die "can not open file out\n";}while(<IN>){if(/^#!/){$_.="## copyright (c) 2012 by Cindy\n";}print OUT "$_";}syntax error at 13.pl line 2, near ") }"
Exxecution of 13.pl aborted due to compilation errors
----------------------
Double行动:
原帖分数:40
帖子加分:40
[解决办法]
- Perl code
#!/usr/bin/env perlopen $fin, '<', 'a.txt' or die "can not open file a.txt\n";open $fout, '>', 'out.txt' or die "can not open file out\n";while (<$fin>) { if (/^#!/) { $_ .= "## copyright (c) 2012 by Cindy\n"; } print $fout "$_";}close $fout;close $fin;
[解决办法]
是"unless",不是"Unless"。
3楼的代码少了一个";"。
