Window 用于附加到文本文件的每一行的 Perl 脚本

Window Perl script for appending to each line of a text file

我想知道如何在这种情况下使用 Perl 附加到文本文件。

我有一个文本文件,它的内容是:

apple,123,456,orange      
cat,789,lion

我在这样的循环中有一个变量

第一个循环:

my $text1 = "hi"
my $text2 = "go"

第二个循环:

my $text1 = "banana"
my $text2 = "car"

我想在文本文件中得到结果

apple,123,456,orange,hi,banana      
cat,789,lion,go,car

我该怎么做?

您没有很好地描述您的问题,似乎忽略了对其他信息的请求。不过,这里有一个程序符合您的描述,可能会对您有所帮助

use strict;
use warnings;

my @extra = (
    [qw/ hi go /],
    [qw/ banana car /],
);

my @data = <DATA>;
chomp @data;

for ( @extra ) {
  my ($text1, $text2) = @$_;
  $data[0] .= ",$text1";
  $data[1] .= ",$text2";
}

print "$_\n" for @data;

__DATA__
apple,123,456,orange
cat,789,lion

输出

apple,123,456,orange,hi,banana
cat,789,lion,go,car