所以我希望我的 perl 文件读取包含两行的文件:
1 10 4
6 4
我希望第一行是@setA,第二行是@setB。我如何在不硬编码的情况下做到这一点?
my $setA = <$fh>; # "1 10 4"
my $setB = <$fh>; # "6 4"
或者
my @setA = split ' ', scalar(<$fh>); # ( 1, 10, 4 )
my @setB = split ' ', scalar(<$fh>); # ( 6, 4 )
use strict;
use warnings;
use autodie qw(:all);
open my $file, '<', 'file.txt';
my @lines = <$file>;
my @setA = $lines[0];
my @setB = $lines[1];
print("@setA");
print("@setB");
close $file;