perl中如何将数组中内容存到一个新建文件中?

2024-12-02 09:18:00
推荐回答(4个)
回答1:

$" = "\n";
@arr = (1, 2, 3, 4, 5);
open OUT, "> a.txt";
print OUT "@arr";

数组内插时,分隔符默认$"的值,可以通过修改$"的值来修改如何分割

回答2:

$" = "\n";
@arr = (1, 2, 3, 4, 5);
open OUT, "> a.txt";
print OUT "@arr";

回答3:

open my $fh, '>' ‘test.txt’ or die $!;
for my $data (@array)
{
print $fh, $data;
}

回答4:

1. use storable;
2. Date::Dumper
3. for my $each1 (@array) {
print OUT $each1
}