我试图简单地弹出每个数值并将它们加在一起以获得总数。
输入文件:
Samsung 46
RIM 16
Apple 87
Microsoft 30
我的代码编译,但是,它只返回 0:
open (UNITS, 'units.txt') || die "Can't open it $!";
my @lines = <UNITS>;
my $total = 0;
while (<UNITS>) {
chomp;
my $line = pop @lines;
$line += $total;
}
print $total;