Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试从文本文件中读取一些数字并将其存储为二维数组。我读了一行并作为数组引用推入另一个数组。但我注意到主数组在所有行中只有最后一行。我该如何纠正这个?提前致谢。这是我做的一部分。
open IN, "a.txt"; @b=(); while (<IN>) { $t =$_; @a = split /\s+/,$t; push(@b, \@a); }
您总共只有两个数组。你想要每行一个,加上@b. my每次执行时都会创建一个新变量,因此您可以使用以下内容:
@b
my
my @b; while (<IN>) { my @a = split; push @b, \@a; }
顺便说一句,您应该始终使用use strict; use warnings;.
use strict; use warnings;