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.
テキスト ファイルからいくつかの数値を読み取り、2 次元配列として保存しようとしています。行を読み取り、配列参照として別の配列にプッシュします。しかし、メイン配列にはすべての行の最後の行しかないことに気付きました。どうすればこれを修正できますか? 前もって感謝します。これは私がする部分です。
open IN, "a.txt"; @b=(); while (<IN>) { $t =$_; @a = split /\s+/,$t; push(@b, \@a); }
合計で 2 つのアレイしかありません。1 行に 1 つ、さらに@b. my実行されるたびに新しい変数を作成するため、次を使用できます。
@b
my
my @b; while (<IN>) { my @a = split; push @b, \@a; }
ちなみに、常に使用する必要がありますuse strict; use warnings;。
use strict; use warnings;