为什么Tie :: File会在文件排序时添加一行?

Ren*_*ger 7 perl tie

我有这个应该对文件进行排序的perl脚本:

#!/usr/bin/perl
use strict;
use warnings;

use Tie::File;

tie my @lines, 'Tie::File', 'fileToBeSorted.txt' or die $!;

printf "line count before: %d\n", scalar @lines;

@lines= sort @lines;

printf "line count after: %d\n", scalar @lines;

untie @lines;
Run Code Online (Sandbox Code Playgroud)

使用此输入运行时(fileToBeSorted.txt)

one;4;1
two;3;2
three;2;3
four;1;4
Run Code Online (Sandbox Code Playgroud)

脚本输出

line count before: 4
line count after: 5
Run Code Online (Sandbox Code Playgroud)

实际上,排序文件包含一个空的第五行.为什么这样,我怎么能防止这种情况?

mob*_*mob 6

如现在删除的答案所述,这似乎是一个已知的错误.

对未解决的列表变量的临时分配是一种解决方法

my @dummy = sort @lines;
@lines = @dummy;
Run Code Online (Sandbox Code Playgroud)

但这对我来说仍然闻起来像个臭虫,你应该报告它.

更新:已经报道(由我们自己的ikegami,不少).Perlmonks 在这里讨论.

  • Credit [@ Squeezy's](http://stackoverflow.com/users/2137516/squeezy)删除了错误报告和perlmonks链接的答案. (3认同)